enumerate(sequence, [start=0])
- sequence:可迭代序列
- strat:迭代序号,可选,默认从0开始
enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标
Return an enumerate object. iterable must be a sequence, an iterator, or some other object which supports iteration. The next() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over iterable.
此函数等价于
1 | def enumerate(sequence, start=0): |
1. 一个简单的例子
1 | iter = range(3) |
2. 官方示例
给出一个官方的例子
1 | seasons = ['Spring', 'Summer', 'Fall', 'Winter'] |