Enumerate枚举
Enumerate()---BIF
主要是对一个元祖或者是一个列表,既要打印元素又要打印索引时使用.
Definition :enumerate(iterable[, start])
Type : Function of__builtin__ module
enumerate(iterable[, start])-> iterator for index, value of iterable
Return an enumerate object.iterable must be another object that supports iteration. The enumerate objectyields pairs containing a count (from start, which defaults to zero) and avalue yielded by the iterable argument. enumerate is useful for obtaining anindexed list:
(0, seq[0]), (1, seq[1]),(2, seq[2]), ...
例子:
a = [a,b,c]
for i,v inenumerate(a):
print I,v
>>> for i, season inenumerate(['Spring', 'Summer', 'Fall', 'Winter']):
...print(i, season)
0 Spring
1 Summer
2 Fall
3 Winter