var or inout parm?

sturlamolden sturlamolden at yahoo.no
Fri Dec 12 07:56:53 EST 2008


On Dec 12, 1:44 pm, "Chris Rebert" <c... at rebertia.com> wrote:

> Python begs to differ, as those two statements are both semantically
> identical in this case:

That is because integers are immutable. When x += 1 is done on an int,
there will be a rebinding. But try the same on say, a numpy array, and
the result will be different:

>>> import numpy
>>> x = numpy.zeros(10)
>>> id(x)
19504848
>>> x += 1
>>> id(x)
19504848
>>> x = x + 1
>>> id(x)
10451488


Whereas:

>>> x = 1
>>> id(x)
10051256
>>> x += 1
>>> id(x)
10051244
>>> x = x + 1
>>> id(x)
10051232







More information about the Python-list mailing list