Bug or feature?
skip at pobox.com
Fri Jan 16 23:51:15 CET 2004
>> Of course, it should be noted that, in Python, "a += b" is only
>> sometimes synonymous with "a = a + b". The rest of the time, it's
>> hard to say what it is synonymous with :)
James> What do you have in mind? J.
For immutable objects, += works as you'd expect: return a new object,
leaving the old object unchanged. That's not the case for mutable objects,
>>> foo = 
>>> bar = foo
>>> foo += 
The object referenced by foo is modified in-place...
>>> foo = foo + 
Here foo is bound to a new object, leaving the old object (still referenced
by bar) unchanged.
[1, 2, 2]
More information about the Python-list