例题:http://oj.oldmoon.cn/p/1012
读入一个n行m列的二维数组
# 方式1,用的最多!!! a = [] for i in range(n): lst = list(map(int, input().split())) a.append(lst)
# 方式2 for i in range(n): lst = [] for j in range(m): lst.append(i*j) a.append(lst)
如果是创建一个常量数组:
# 创建一个3x4的二维数组 matrix = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12] ]
#1:输出整个数组 for i in range(n): for j in range(m): print(a[i][j], end = " ") print() #2:查询 print(a[1][2]) #3: 修改 a[2][1] = 100
On This Page