[Tutor] Copying a mutable

Válas Péter sulinet at postafiok.hu
Wed Jun 8 00:38:01 CEST 2011


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). How is that, what is the explanation? Meanwhile the same for
immutable types results a real copy, and so does for simple mutables such as
int.

I suspect it has something to do with pointers, but what is the difference
between mutables and immutables, and why have they different id's if they
are the same?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110608/696415c3/attachment.html>


More information about the Tutor mailing list