3 ms·
Not that I ever had problem with it, but ambiguity with ++ lies in prefix/postfix version of the operator. I don't see how x+=1 is ambiguous in any way, it's ju
by ivanhoe 6y ago
Not that I ever had problem with it, but ambiguity with ++ lies in prefix/postfix version of the operator. I don't see how x+=1 is ambiguous in any way, it's just a shorter way to write it, but there's no side-effects like with x++?
- beagle3 6y agoThere is no ambiguity. Prefix is increment pre (increment before getting the value). Postfix is increment post (increment after getting the value). Both have side effects as does x+=1. consider the call f(x+=1,x+=1) when x=5; what is the call? f(6,7) or f(7,6)? Iirc even f(6,6) and f(7,7) were valid behavior in the past.
- ptx 6y ago"x += 1" in Python is a statement, not an expression, so that's a SyntaxError. But I suppose you would run into this kind of ambiguity with the walrus operator, i.e. >>> x = 5 >>> f = lambda a, b: (a, b) >>> print(f(x := x + 1, x := x + 1)) (6, 7) PEP 572 appears[1] to specify that the evaluation order should always be left to right. [1] https://www.python.org/dev/peps/pep-0572/#change-to-evaluation-order https://www.python.org/dev/peps/pep-0572/#change-to-evaluati...