码迷,mamicode.com
首页 > 编程语言 > 详细

python中的enumerate函数

时间:2017-02-10 17:20:15      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:python   int   pytho   for   元素   nbsp   序列   print   rate   

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

python中的enumerate函数

标签:python   int   pytho   for   元素   nbsp   序列   print   rate   

原文地址:http://www.cnblogs.com/kele-1314/p/6387108.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!