Python中for循环使用enumerate() 函数

Python中for循环使用enumerate() 函数

enumerate()是python的内置函数、适用于python2.x和python3.x
enumerate参数为可遍历/可迭代的对象(如列表、字符串、元组)

实例:


>>>seq = ['one', 'two', 'three']
>>> for i, element in enumerate(seq):
...     print i, element
... 
0 one
1 two
2 three

你可能感兴趣的:(python,列表,django)