enumerate函数接受一个可遍历的对象,如列表.字符串,可同时遍历下标(index)及元素值(value) >>> a = ['aaa','bbb','ccc',1235] >>> print(a) ['aaa', 'bbb', 'ccc', 1235] >>> print(len(a)) 4 >>> for i in range(len(a)): print(i) 0 1 2 3 >>> for j in ra…
列表是最常用的Python数据类型,前段时间看书的时候,发现了enumerate() 函数非常实用,因为才知道下标可以这么容易的使用,总结一下. class enumerate(object): """ Return an enumerate object. iterable an object supporting iteration The enumerate object yields pairs containing a count (from start, whic…
enumerate函数用于遍历序列中的元素以及它们的下标 i = 0 seq = ['one', 'two', 'three'] for element in seq: print i, seq[i] i += 1 #0 one #1 two #2 three print '============' seq = ['one', 'two', 'three'] for i, element in enumerate(seq): print i, seq[i] print '===========…
enumerate字典上是枚举.列举的意思. C语言中关键字enum也是enumerate的缩写. python中enumerate方法,返回一个enumerate类型.参数一般是可以遍历的的东西,比如列表,字符串什么的. python文档中是这么说的: enumerate(sequence, [start=0]) Return an enumerate object. sequence must be a sequence, an iterator, or some other…