Is behavior of += intentional for int?

Paul McGuire ptmcg at austin.rr.com
Sun Aug 30 06:52:36 EDT 2009


On Aug 30, 5:42 am, Paul McGuire <pt... at austin.rr.com> wrote:
> Python binds values to names. Always. In Python, "=" is not and never
> could be a class operator.  In Python, any expression of LHS = RHS,
> LHS is always a name, and in this statement it is being bound to some
> object found by evaluating the right hand side, RHS.
>
An interesting side note, and one that could be granted to the OP, is
that Python *does* support the definition of class operator overrides
for in-place assignment operators like += (by defining a method
__iadd__).  This is how numpy's values accomplish their mutability.

> It is surprising how many times we
> think things are "intuitive" when we really mean they are "familiar".
Of course, just as I was typing my response, Steve D'Aprano beat me to
the punch.

Maybe it's time we added a new acronym to this group's ongoing
discussions: PDWTW, or "Python doesn't work that way".

-- Paul



More information about the Python-list mailing list