您的位置:首页 > 编程语言 > Python开发

python中enumerate函数用法

2017-07-13 10:50 337 查看
这两位博主写的都很好

http://blog.csdn.net/churximi/article/details/51648388

http://blog.sina.com.cn/s/blog_a299c85e0101h3y4.html

enumerate 函数用于遍历序列中的元素以及它们的下标:

>>> for i,j in enumerate(('a','b','c')):

 print i,j

 

0 a

1 b

2 c

>>> for i,j in enumerate([1,2,3]):

 print i,j

 

0 1

1 2

2 3

>>> for i,j in enumerate({'a':1,'b':2}):

 print i,j

 

0 a

1 b

>>> for i,j in enumerate('abc'):

 print i,j

 

0 a

1 b

2 c
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: