enumerate(sequence, [start=0])
enumerate()函数一般用在for循环中,参数为序列,迭代器或者是可以迭代的对象。
举个栗子:
list = ['one','two','three']
for index,item in enumerate(list):
print(index,item)
输出:
0 one
1 two
2 three
指定start后
list = ['one','two','three']
for index,item in enumerate(list, start=1):
print(index,item)
输出:
1 one
2 two
3 three