Python中遍歷二維數組有多種方法,以下是常見的幾種方法:
array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
for i in range(len(array)):
for j in range(len(array[i])):
print(array[i][j])
array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
for row in array:
for element in row:
print(element)
array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
result = [element for row in array for element in row]
print(result)
這些方法都可以用于遍歷二維數組,根據具體需求選擇合適的方法。