pythn3随笔-enumerate()

版权声明:本博客所有文章版权归博主刘兴所有,转载请注意来源 https://blog.csdn.net/AI_LX/article/details/89669550

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

>>>seq = ['one', 'two', 'three']
>>>for i, element in enumerate(seq):
...    print(i, seq[i])
... 
0 one
1 two
2 three
>>>

猜你喜欢

转载自blog.csdn.net/AI_LX/article/details/89669550