Tom Culliton culliton at clark.net
Sat Mar 25 16:55:44 CET 2000

In article <uPYC4.55946$3b6.224410 at ozemail.com.au>,
Jason Stokes <jstok at bluedog.apana.org.au> wrote:
>Hrvoje Niksic wrote in message ...
>>The crux of the matter is: a and b are not objects that point to
>>numbers; they are variables that refer (point) to numbers, which are
>Incidently: does the term "variable" have any formal meaning within Python?
>The Python docs seem only to talk about "names".

No it doesn't, and there's a reason for this.  "Variable" implies a
different way of handling names and storage.  In most languages a
variable is named piece of storage, the name is tightly bound to that
location and values of a particular type are move in and out of the
space or even modified in place.  The situation in python is rather
different, the name is merely a label that is temporarily attached to
a storage object (which may be immutable like numbers and strings) and
can just as well be attached to any other object.

Lets illustrate with an example:

In "C" saying:

	x = x + 1
	y = x

means to get the value of location x, add one to it, store the result
back in location x, and finally copy the value from location x into
location y.  In Python the same statement means to get the (immutable)
object refered to by x add 1 too it producing a _new_ object, bind the
name x to that new object, and finally also bind the name y to that
new object.  Afterwards taking the address of x and y in C would give
you two _different_ locations, whereas taking the id of x and y would
give you the _same_ value because both names refer to the same object.

More information about the Python-list mailing list