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
转载于:https://blog.51cto.com/gyp150/1348696
Python enumerate() 函数详解
本文详细介绍了Python内置函数enumerate()的用法及其参数设置,通过实例演示了如何利用enumerate()函数来遍历列表或其他可迭代对象,并获取元素及其对应的索引。
647

被折叠的 条评论
为什么被折叠?



