I understand that when you do a shallow copy of a dictionary, you actually make a copy of the references. So if I do this:
x={'key':['a','b','c']}
y=x.copy()
So the reference of the list ['a','b','c'] is copied into y. Whenever I change the list ( x['key'].remove('a')
for example), both dict x and y will change. This part I understand. But when I consider situation like this below:
x={'user':'admin','key':['a','b','c']}
y=x.copy()
When I do y['user']='guest'
, x['user'] will not change, but the list still shares the same reference.
So my question is what makes the string different than the list? What is the mechanism behind this?