3 ms·
"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
by 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...