我写了这段代码:
if __name__ == "__main__" :
lst = []
current= []
for i in range(3):
print(current)
print(lst)
lst.append(current)
print(lst)
current.append(i)
我希望它打印:
[]
[]
[[]]
[0]
[[]]
[[],0]
[0,1]
[[],0]
[[],0,[0,1]]
但相反它打印:
[]
[]
[[]]
[0]
[[0]]
[[0], [0]]
[0, 1]
[[0, 1], [0, 1]]
[[0, 1], [0, 1], [0, 1]]
我不明白为什么lst
将其成员更改为当前成员。
分析解答