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

posted @ 2014-06-17 17:07  蓝夜  阅读(193)  评论(0编辑  收藏  举报