enumerate是python 2.3中新增的内置函数,它的英文说明为:

enumerate( iterable)

Return an enumerate object. iterable must be a sequence, an iterator,or some other object which supports iteration. The next() method ofthe iterator returned by enumerate() returns a tuple containing acount (from zero) and the corresponding value obtained from iteratingover iterable. enumerate() is useful for obtaining an indexed series:(0, seq[0]), (1, seq[1]), (2, seq[2]), .... New in version 2.3.


>> s = ['abc', 'This is a test', 'Hello, Python']
>> for i, line in enumerate(s):
>> print i+1, line

标签: Python