logoalt Hacker News

kccqzytoday at 3:58 PM1 replyview on HN

It’s assigned left to right, not right to left. It’s documented in the Python language reference.

> An assignment statement evaluates the expression list and assigns the single resulting object to each of the target lists, from left to right.

Consider this:

    a = [1, 2]
    i = a[i] = 1
If assignment were to happen right to left, you would get a NameError exception because the first assignment would require an unbound variable.

Replies

mathisfun123today at 4:40 PM

Fine but that even moreso illustrates how goofy the expectation that the "ctor" for [] would be called twice.