python之enumerate()函数的探究

时间:2014-06-18 09:59:20   收藏:0   阅读:217

原地址: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] 
相比较而言,前者更简练
_

python之enumerate()函数的探究,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!