Re:Python becomes a platform. Thoughts on the release of clo...
by DanWaterworth on Friday March 16, 2012 @02:32AM
(#3712249)
No, I had to check that, but it doesn't appear to be true. `id` uses the ptr of the object in CPython, and:
>>> a = 1
>>> id(a)
32855992
>>> a += 1
>>> id(a)
32855968
So it's actually creating a new Integer object, which `a` then points to, or in other words: a += 1 is equivalent to a = a + 1
This behavior makes sense, if you wrote: a = 10
b = a
a += 20
You wouldn't expect b to be 30.
Immutable? Could you explain this a bit more? (As far as I know, "x += 1" will modify the block of memory that x points to)