Function article——enumerate()

enumerate(): For an iterable/traversable object (such as a list, string), the enumerate function forms an index sequence, which can be used to obtain both the index and the value.

list = ["这", "是", "小", "测"]
for index, item in enumerate(list1):
    print index, item
>>>
0 这
1 是
2 小
3 测
a=[1,2,3,4,5,6]
for k ,v in enumerate(a):
    print(k,v)

>>>
0 1
1 2
2 3
3 4
4 5
5 6

Guess you like

Origin blog.csdn.net/weiyuangong/article/details/125812229