enumerate()函数

enumerate()函数主要用于记录循环的loop循环的索引,起始值为0。

1  >>>l=[1,2,3]
2  >>>for (i,j) in enumerate(l):
3        print("the %ith element in the list is %d" % (i,j))
4 运行结果:
5 the 0th element in the list is 1
6 the 1th element in the list is 2 
7 the 2th element in the list is 3

posted on 2020-04-29 16:10  lin195312  阅读(77)  评论(0)    收藏  举报

导航