python中清空字典

1、

>>> a = dict(zip(["one","two","three"],[100,200,300]))
>>> a
{'one': 100, 'two': 200, 'three': 300}
>>> b = a
>>> b
{'one': 100, 'two': 200, 'three': 300}
>>> a = {}
>>> a
{}
>>> b
{'one': 100, 'two': 200, 'three': 300}

2、

>>> a = dict(zip(["one","two","three"],[100,200,300]))
>>> a
{'one': 100, 'two': 200, 'three': 300}
>>> b = a
>>> b
{'one': 100, 'two': 200, 'three': 300}
>>> del a
>>> a
Traceback (most recent call last):
  File "<pyshell#1339>", line 1, in <module>
    a
NameError: name 'a' is not defined
>>> b
{'one': 100, 'two': 200, 'three': 300}

3、

>>> a = dict(zip(["one","two","three"],[100,200,300]))
>>> a
{'one': 100, 'two': 200, 'three': 300}
>>> b = a
>>> b
{'one': 100, 'two': 200, 'three': 300}
>>> a.clear()
>>> a
{}
>>> b
{}
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14220727.html