获取某个元素在循环中的位置

5 四月, 2006 (11:56) | python

python 中有enumerate函数,可以返回元素在循环中的位置,例如:

xx=[’a', ‘b’, ‘c’, ‘d’]

for x in enumerate(xx):

print x

返回结果如下:

(0, ‘a’)

(1, ‘b’)

(2, ‘c’)

(3, ‘d’)

Write a comment





提示:如果你刚刚提交过评论,但是还没有被显示出来,请点击这里刷新一下: 刷新评论