(Don\'t worry, this isn\'t another question about unpacking tuples.)
In python, a statement like foo = bar = baz = 5
assigns the variables foo, bar, and
All credit goes to @MarkDickinson, who answered this in a comment:
Notice the
+
in(target_list "=")+
, which means one or more copies. Infoo = bar = 5
, there are two(target_list "=")
productions, and theexpression_list
part is just5
All target_list
productions (i.e. things that look like foo =
) in an assignment statement get assigned, from left to right, to the expression_list
on the right end of the statement, after the expression_list
gets evaluated.
And of course the usual 'tuple-unpacking' assignment syntax works within this syntax, letting you do things like
>>> foo, boo, moo = boo[0], moo[0], foo[0] = moo[0], foo[0], boo[0] = [0], [0], [0]
>>> foo
[[[[...]]]]
>>> foo[0] is boo
True
>>> foo[0][0] is moo
True
>>> foo[0][0][0] is foo
True