Hi,

2011/6/7 Válas Péter <suli...@postafiok.hu>

> Hi,
>
> let X be a mutable container, such as dict/set/list=bytearray, and Y=X,
> When I change X, Y will follow it, having always the same value, although
> id(X)!=id(Y).


That's not correct:

Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on
win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> x=[1,2,3]
>>> y=x
>>> id(x)
36115464L
>>> id(y)
36115464L
>>> x.append(4)
>>> id(x)
36115464L
>>> id(y)
36115464L
>>> x
[1, 2, 3, 4]
>>>

As you can see, x and y are references to the same object (e.g. with the
same id.)

Regards

Walter
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to