在Python中,可以使用多種方法來遍歷數組,包括:
arr = [1, 2, 3, 4, 5]
for element in arr:
print(element)
arr = [1, 2, 3, 4, 5]
index = 0
while index < len(arr):
print(arr[index])
index += 1
arr = [1, 2, 3, 4, 5]
for index, element in enumerate(arr):
print(f"Index {index}: {element}")
arr1 = [1, 2, 3]
arr2 = ['a', 'b', 'c']
for element1, element2 in zip(arr1, arr2):
print(f"{element1} - {element2}")
arr = [1, 2, 3, 4, 5]
[print(element) for element in arr]
這些方法可以根據具體需求選擇合適的方式來遍歷數組。