标签:... sum start ring 序列 star index print ons
enumerate()
enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。
以下是 enumerate() 方法的语法:
enumerate(sequence, [start=0])
示例
示例
>>>i = 0
>>>seq = [‘one‘, ‘two‘, ‘three‘]
>>>for element in seq:
... print(i, seq[i])
... i += 1
...
0 one
1 two
2 three
>>>seq = [‘one‘, ‘two‘, ‘three‘]
>>>for i, element in enumerate(seq):
... print(i, seq[i])
...
0 one
1 two
2 three
>>>
示例
for i in enumerate(list):
print(i)
for index,i in enumerate(list):
print(index,i)
标签:... sum start ring 序列 star index print ons
原文地址:https://www.cnblogs.com/fmgao-technology/p/9038492.html