1
我有點困惑這是如何工作的。Python引用附加列表
x = []
y = []
for i in range(5):
y.append(i) # Why does this create full copies of sub lists?
x.append(y)
#x.extend(y) # This works normal
print x
爲什麼x.append(y)
告誡最終結果如下?你能否解釋一下是否有一些背景參考值?
[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]