enumerate函数
enumerate(iterable, start=0)
__next__()方法
# 枚举可迭代对象a a = ['Mary', 'had', 'little'] for i, e in enumerate(a): print(i, e)
# 列出枚举对象 seasons = ['Spring', 'Summer', 'Fall', 'Winter'] print(list(enumerate(seasons)))
# 等价函数 def enumerate(sequence, start=0): n = start for elem in sequence: yield n, elem n += 1
更多:
Loop Methods 循环技巧