【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]]

 

posted @ 2021-08-04 15:40  氦呀  阅读(271)  评论(0编辑  收藏  举报