如何在python中迭代数组时输出索引
这个问题在这里已经有了答案:
喜欢这个:
for index, g in enumerate(games[0:4]):
g.output(index)
使用内置的enumerate
方法:
for i,a in enumerate(['cat', 'dog']):
print '%s is %d' % (a, i)
# output:
# cat is 0
# dog is 1
链接地址: http://www.djcxy.com/p/24003.html
上一篇: How to output an index while iterating over an array in python
下一篇: How to get list index and element simultaneously in Python?