[Tutor] Copying a mutable
Wayne Werner
waynejwerner at gmail.com
Wed Jun 8 01:02:01 CEST 2011
Apologies for the top post, my phone doesn't allow editing the message body.
You are slightly confused - ints are not mutable! You can combine or
multiply them, along with several other operations, but they are certainly
not mutable. The easiest way to check is use them as keys in a dict. You
can't do that with lists or other mutable types. Since I don't have computer
access right now I can't look up the docs on id, but hopefully someone else
can enlighten you. But ints are definitely immutable. I suspect you're
confusing the fact that you can easily reassign ints with mutability.
HTH,
Wayne
On Jun 7, 2011 5:50 PM, "Válas Péter" <sulinet at postafiok.hu> wrote:
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?
_______________________________________________
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110607/ee307841/attachment-0001.html>
More information about the Tutor
mailing list