Return value of an assignment statement?

Jeff Schwab jeff at schwabcenter.com
Fri Feb 22 14:23:27 EST 2008


George Sakkis wrote:
> On Feb 22, 12:26 am, Jeff Schwab <j... at schwabcenter.com> wrote:
> 
>>> On the other hand, "a = b" does always the same thing; unlike C++, '='
>>> is not an operator and therefore it cannot be overriden by the class
>>> of 'a'.
>> "Not an operator?"  Then what is it?
> 
> In this context, it's just the token used for the assignment
> statement. In short, if 'a' is an identifier, the statement means
> "bind the name 'a' to the object 'b' (in the local or global
> namespace)". It doesn't say anything about memory allocation,
> initialization or copying. The only case where assigning an identifier
> affects memory is the following [1]:
> 
> """
> The name is rebound if it was already bound. This may cause the
> reference count for the object previously bound to the name to reach
> zero, causing the object to be deallocated and its destructor (if it
> has one) to be called.
> """
> 
> [1] http://docs.python.org/ref/assignment.html

OK, thanks for trying to make it clear.

I'm about through with this discussion, but FWIW, this is a real gotcha 
for me and many others.  This is a case where Python does not do what 
many programmers expect, and it at least takes some getting used-to.



More information about the Python-list mailing list