a = [[0] * 4] * 4
id = 0
for i in range(4):
for j in range(4):
a[i][j] = copy.deepcopy(id)
id += 1
print(a)
实际输出:
[[12, 13, 14, 15], [12, 13, 14, 15], [12, 13, 14, 15], [12, 13, 14, 15]]
我希望的输出:
[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]