That might be the case for more complex objects...
b.r.willems at gmail.com
Sat Apr 14 22:03:03 CEST 2007
Dennis Lee Bieber wrote:
> On 14 Apr 2007 06:35:34 -0700, "jamadagni" <samjnaa at gmail.com> declaimed
> the following in comp.lang.python:
> In Python, the "variable" NAME does NOT define storage; unlike most
> other classical languages where the "variable name" is a storage
> address, and the value of the RHS is COPIED to that address. Python does
> not do such copying. Names are references to the RHS object itself.
> a = 5
> means that somewhere in memory is an integer object with the value "5";
> the name "a" is now "pasted onto" that integer object.
> b = a
> finds the object that has the name "a" stuck to it, and sticks a second
> name "b" onto the same object. There is still only one "5" in memory.
I can try this in interactive mode:
>>> a = 5
>>> b = a
>>> a += 1
>>> print b
So, if /a/ and /b/ where pointing to the *same* "5" in memory, then I
would expect b to be increased, just as a. But after increasing a, b is
Lists behave as described above, integers and floats don't.
By the way, a classic language like C has features like this too;
they're called pointers.
More information about the Python-list