Return value of an assignment statement?

Duncan Booth duncan.booth at invalid.invalid
Fri Feb 22 04:31:43 EST 2008


Jeff Schwab <jeff at schwabcenter.com> wrote:

> a += b
> 
> Whether a refers to the same object before and after that statement 
> depends on what type of object it referred to before the statement.
> 
Yes but the rule followed by the builtin types is pretty simple: if 'a' can 
still refer to the same object then it does.

Immutable objects make this impossible most of the time (unless 'b' is 0, 
(), or similar), and there may be other exceptions I've missed, but this is 
the general principle, so mutable objects will mutate and immutable objects 
won't.

Whether the same rule is followed outside the core is, of course, up to the 
individual developers.



More information about the Python-list mailing list