python 循环中使用index索引
# 使用enumerate()实现
ints = [8, 23, 45, 12, 78]
for idx, val in enumerate(ints):
print(idx, val)
ints = [8, 23, 45, 12, 78]
for index, item in enumerate(ints, start=0): # 默认是从 0 开始
print(index, item)
ints = [8, 23, 45, 12, 78]
for index, item in enumerate(ints, start=1): # 索引修成从 1 开始
print(index, item)