Re:PEP 572: Python assignment expressions has been accepted
by blattimwind on Tuesday July 03, 2018 @08:27AM
(#17449560)
> because it parses the same
Does not. One is addition, the other is in-place addition; they're different things and can behave differently. E.g. in "a += b" and "a = a + b", the former might not construct an intermediate object, but mutate the existing a.
Re:PEP 572: Python assignment expressions has been accepted
by ben-schaaf on Tuesday July 03, 2018 @10:45AM
(#17450607)
To be more specific for python:
"a += b" -> "a = a.__iadd__(b)"
"a = a + b" -> "a = a.__add__(b)"
"__iadd__" and "__add__" can do whatever they want.
The sugar is sprinkled on top of syntax, the stuff the parser deals with. Typing a += 1 instead of a = a + 1 is sugar because it parses the same. This assignment syntax seems different. IMHO.