Message111069
On Wed, Jul 21, 2010 at 2:09 AM, Ray.Allen <report@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/ |
|
Date |
User |
Action |
Args |
2010-07-21 14:35:21 | belopolsky | set | recipients:
+ belopolsky, amaury.forgeotdarc, djc, eric.araujo, ysj.ray |
2010-07-21 14:35:19 | belopolsky | link | issue9314 messages |
2010-07-21 14:35:18 | belopolsky | create | |
|