[Python-ideas] Why does += trigger UnboundLocalError?
Ethan Furman
ethan at stoneleaf.us
Thu Jun 2 01:47:19 CEST 2011
Steven D'Aprano wrote:
> Carl M. Johnson wrote:
>
>> Agreed, sure, we have to treat the LHS of = as
>> a local. But += is fundamentally different.
>
>
> No it's not. It is fundamentally the same. Augmented assignment in
> Python *is* assignment, equivalent to x = x.__iadd__(other).
Or x = x.__add__(other) if no __iadd__ exists for the object.
~Ethan~
More information about the Python-ideas
mailing list