【Python】二维列表
两种写法如下:
a = []
for i in range(3):
a.append([])
print(a)
for j in range(4, 9):
a[i].append(j)
print(a)
输出:
[[]]
[[4, 5, 6, 7, 8], []]
[[4, 5, 6, 7, 8], [4, 5, 6, 7, 8], []]
[[4, 5, 6, 7, 8], [4, 5, 6, 7, 8], [4, 5, 6, 7, 8]]
A = [[i for i in range(4, 9)] for i in range(3)]
print(A)
输出:
[[4, 5, 6, 7, 8], [4, 5, 6, 7, 8], [4, 5, 6, 7, 8]]