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
{}

 

posted @ 2021-01-01 19:47  小鲨鱼2018  阅读(371)  评论(0编辑  收藏  举报