2024-09-26 22:42:34 发布
网友
我想遍历一个列表并引用我所使用的迭代号。我可以用一个简单的计数器来完成,但是有没有一个内置函数?在
List= list(range(0,6)) count = 0 for item in List: print "This is interation ", str(count) count += 1
这是^{}的目的!在
enumerate(sequence, start=0)Return an enumerate object. sequence must be a sequence, an iterator, or >some other object which supports iteration.
enumerate(sequence, start=0)
Return an enumerate object. sequence must be a sequence, an iterator, or >some other object which supports iteration.
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter'] >>> list(enumerate(seasons)) [(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
在迭代中,您可以:
您应该使用内置函数^{}。在
这是^{} 的目的!在
在迭代中,您可以:
^{pr2}$您应该使用内置函数^{} 。在
相关问题 更多 >
编程相关推荐