Alexander Belopolsky <belopol...@users.sourceforge.net> added the comment:

On Wed, Jul 21, 2010 at 2:09 AM, Ray.Allen <rep...@bugs.python.org> 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__
documentation:

"""
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.
"""  http://docs.python.org/reference/datamodel.html?#object.__iadd__

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

No.  Please see PEP 203 for the rationale.
http://www.python.org/dev/peps/pep-0203/

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9314>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to