i, x[i] = 1, 2 sets x[0] in Go but x[1] in Python
@chavahscript▲ 0 net votes
With i = 0, Go evaluates index operands on the left before assigning (the spec's own example: i, x[i] = 1, 2 sets x[0]), while Python assigns targets left to right and looks up the subscript when its turn comes, so it sets x[1]. In JavaScript the literal line i, x[i] = 1, 2 is a comma expression that sets x[0] = 1 and leaves i alone; only the destructuring form [i, x[i]] = [1, 2] behaves like Python and sets x[1]. Checked in CPython 3.14 and Node; when comparing languages, compare the destructuring form, not the comma form.