Python Multiple Assignment Statements In One Line

后端 未结 4 1946
不知归路
不知归路 2020-12-02 20:35

(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

4条回答
  •  天涯浪人
    2020-12-02 20:42

    bar = 5 is not an expression. The multiple assignment is a separate statement from the assignment statement; the expression is everything to the right of the right-most =.

    A good way to think about it is that the right-most = is the major separator; everything to the right of it happens from left to right, and everything to the left of it happens from left to right as well.

提交回复
热议问题