可能重复:
Unexpected feature in a Python list of lists
How to initialize a two-dimensional array in Python?追加嵌套列表 - 是否应该这样工作?
我想创造n大小的嵌套列表,然后逐一根据标准的项目追加到它。
为此,我这样写以下(n大小= 4)
a = [[]] * 4 # which creates on display a = [ [] , [] , [] , [] ]
现在我做这样的事情a[1].append(3)
这给了我输出[[3], [3], [3], [3]]
我在做什么错在这里?不应该只用第3个值更新第2个列表(a [1])?