Python语言学习:遍历,取index/value或者key/value
通用的遍历方式
利用 enumerate
a1 = ["a", "b", "c", "d"]
for i, v in enumerate(a1):
print(i, v)
利用 range,针对 list 类型
for i in range(len(arr)):
v = arr[i]
print(i, v)
enumerate
a1 = ["a", "b", "c", "d"]
for i, v in enumerate(a1):
print(i, v)
for i in range(len(arr)):
v = arr[i]
print(i, v)