内置函数enumerate()使用

描述

enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。

Python 2.3. 以上版本可用,2.6 添加 start 参数。

>>>seq = ['one', 'two', 'three']

>>> for i, element in enumerate(seq):

>>> print(ielement  ...

    0 one

    1 two

    2 three

猜你喜欢

转载自www.cnblogs.com/mys6/p/10554984.html