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)
这些方法都可以用于遍历二维数组,根据具体需求选择合适的方法。