2 ms·
There is no ambiguity. Prefix is increment pre (increment before getting the value). Postfix is increment post (increment after getting the value). Both have si
by beagle3 6y ago
There 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...