python assignment
dan
danbmil99 at yahoo.com
Tue Jul 22 20:59:08 EDT 2003
without stirring the pot too much --
could someone please point me to whatever documentation exists on the
philosophy, semantics, and practical implications of how Python
implements the assignment operator? So far I can't find much useful
in the regular documentation. I understand the basic concept that
names are bound to objects which exist on the heap, but that still
doesn't explain why a = b doesn't _always_ cause a to point to the
same object as b. What determines when the object in question is
copied? What determines when a future maniplulation of the variable
will cause it to point to an object that is already referenced by
another variable? (see code below for an example).
What I need is an exact and unambiguous algorithm for determining when
an assignment will change the id of the variable (or should I say,
when the evaluation of an expression will cause a new object to be
created). Some of the issues involved can be discerned from the
following session:
>>> a = 1
>>> b = a
>>> a is b
True
>>> a += 1
>>> a -= 1
>>> a is b
True
>>> a = 1.0
>>> b = a
>>> a is b
True
>>> a += 1
>>> a -= 1
>>> a is b
False
>>> a == b
True
More information about the Python-list
mailing list