python中clear和clear()

python中clear和clear()
clear只会清除列表,不会删除数值所在的地址空间,
clear()会删除地址空间,导致这些值被清空无法存储

a=[1,2]
b=[]
b.append(a)
b.append(a)
a.clear
print(b)
a.clear()
print(b)
'''
[[1, 2], [1, 2]]
[[], []]
'''

你可能感兴趣的:(python,list,列表)