首页 > 代码库 > python之enumerate()函数的探究
python之enumerate()函数的探究
原地址:http://www.newsmth.net/nForum/#!article/Python/95860
最近用到enumerate()函数,于是查了相关的资料。
其中的一篇是这样的:一般情况下,如果要对一个列表或者数组既要遍历索引又要遍历元素时,可以用enumerate
比如:
for index,value in enumerate(list):
print index,value
当然也可以
for i in range(0,len(list)):
print i,list[i]
相比较而言,前者更简练_
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。