Author belopolsky
Recipients amaury.forgeotdarc, belopolsky, djc, eric.araujo, ysj.ray
Date 2010-07-21.14:35:18
SpamBayes Score 0.000125154
Marked as misclassified No
Message-id <>
In-reply-to <>
On Wed, Jul 21, 2010 at 2:09 AM, Ray.Allen <> wrote:
> Does this means "a += b" is not the same as "a = a + b"?

For immutable a, the two are practically the same, for mutable, they
are necessarily different.   This is explained in __iadd__

These methods are called to implement the augmented arithmetic
assignments (+=, -=, *=, /=, //=, %=, **=, <<=, >>=, &=, ^=, |=).
These methods should attempt to do the operation in-place (modifying
self) and return the result (which could be, but does not have to be,
self). If a specific method is not defined, the augmented assignment
falls back to the normal methods. For instance, to execute the
statement x += y, where x is an instance of a class that has an
__iadd__() method, x.__iadd__(y) is called. If x is an instance of a
class that does not define a __iadd__() method, x.__add__(y) and
y.__radd__(x) are considered, as with the evaluation of x + y.

> I'd think this can be seen as a pitfall for python.

No.  Please see PEP 203 for the rationale.
Date User Action Args
2010-07-21 14:35:21belopolskysetrecipients: + belopolsky, amaury.forgeotdarc, djc, eric.araujo, ysj.ray
2010-07-21 14:35:19belopolskylinkissue9314 messages
2010-07-21 14:35:18belopolskycreate