Consider this
dict1={}
dict2={}
dict2["first_d2"]="Yes"
dict1["first_d1"]=dict2
print dict1
print dict2
dict2={}
print dict1 ===>Here's the doubt
print dict2
The Output:
{'first_d1': {'first_d2': 'Yes'}}
{'first_d2': 'Yes'}
{'first_d1': {'first_d2': 'Yes'}} ===>Why is this not resetting?Its referencing to dict2
{}
Now python dictionaries are mutable.So dict1 is referencing to dict2.Now after first operation dict2 is reset,why is the value of dict1 not resetting?
As per my understanding mutable object change the contents in memory and do not return a new object.So why is this not happening here?What am i missing?
I am confused from the point of view of mutable and immutable!