Am 13.01.2012 13:30 schrieb Chris Angelico:

It seems there's a distinct difference between a+=b (in-place
addition/concatenation) and a=a+b (always rebinding),

There is indeed.

a = a + b is a = a.__add__(b), while

a += b is a = a.__iadd__(b).

__add__() is supposed to leave the original object intact and return a new one, while __iadd__() is free to modify (preference, to be done if possible) or return a new one.

A immutable object can only return a new one, and its __iadd__() behaviour is the same as __add__().

A mutable object, however, is free to and supposed to modify itself and then return self.


Thomas
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to