Python Copy Through Assignment?
Posted
by Marcus Whybrow
on Stack Overflow
See other posts from Stack Overflow
or by Marcus Whybrow
Published on 2010-03-13T15:47:48Z
Indexed on
2010/03/13
15:55 UTC
Read the original article
Hit count: 367
python
I would expect that the following code would just initialise the dict_a
, dict_b
and dict_c
dictionaries. But it seams to have a copt through effect:
dict_a = dict_b = dict_c = {}
dict_c['hello'] = 'goodbye'
print dict_a
print dict_b
print dict_c
As you can see the result is as follows:
{'hello': 'goodbye'}
{'hello': 'goodbye'}
{'hello': 'goodbye'}
Why does that program give the previous result, When I would expect it to return:
{}
{}
{'hello': 'goodbye'}
© Stack Overflow or respective owner