【发布时间】:2022-10-25 05:47:05
【问题描述】:
我在python中有以下非常简单的实现
m = []
l = []
l.append('A')
l.append('B')
l.append('C')
m.append(l)
l.clear()
print(m) --> this gives empty list.
我试过了
m = []
l = []
n = []
l.append('A')
l.append('B')
l.append('C')
n = l
m.append(n)
l.clear()
print(m) --> this gives empty list too
但是当我不清除 l 时,print(m) 会给我想要的列表,即 ['A','B','C']。为什么当我清除列表 l 时 python 会清除列表 m。它们是两个独立的变量?
【问题讨论】: