【发布时间】:2015-06-10 08:45:17
【问题描述】:
考虑一下
dict1={}
dict2={}
dict2["first_d2"]="Yes"
dict1["first_d1"]=dict2
print dict1
print dict2
dict2={}
print dict1 ===>Here's the doubt
print dict2
输出:
{'first_d1': {'first_d2': 'Yes'}}
{'first_d2': 'Yes'}
{'first_d1': {'first_d2': 'Yes'}} ===>Why is this not resetting?Its referencing to dict2
{}
现在python字典是可变的。所以dict1引用dict2。现在在第一次操作dict2被重置后,为什么dict1的值没有被重置?
根据我的理解,可变对象更改内存中的内容并且不返回新对象。那么为什么这里没有发生这种情况?我错过了什么?
从可变和不可变的角度来看,我很困惑!
【问题讨论】:
标签: python python-2.7 dictionary