Python enumerate函数心得笔记
功能:
enumerate()是Python的内置函数,用于将一个可遍历的数据对象(如列表、元组或字符串等)组合为一个索引序列,同时列出数据和数据下标,多用于for循环
语法:
enumerate(a,start)
a是可迭代对象,start是计数起始数字
示例一:
1 li = ["a","b","c","d","e","f"]
2
3 for i in enumerate(li):
4 print(i)
结果:
(0, 'a')
(1, 'b')
(2, 'c')
(3, 'd')
(4, 'e')
(5, 'f')
示例二:
li = ["a","b","c","d","e","f"]
for i in enumerate(li,1):
print(i)
结果:
(1, 'a')
(2, 'b')
(3, 'c')
(4, 'd')
(5, 'e')
(6, 'f')
相关推荐
elizabethxxy 2020-11-06
夜斗不是神 2020-11-17
huavhuahua 2020-11-20
Yasin 2020-11-16
xiaoseyihe 2020-11-16
千锋 2020-11-15
diyanpython 2020-11-12
chunjiekid 2020-11-10
wordmhg 2020-11-06
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16