Multiple assignment and evaluation order in Python

前端 未结 10 1913
醉酒成梦
醉酒成梦 2020-11-22 01:41

What is the difference between the following Python expressions:

# First:

x,y = y,x+y

# Second:

x = y
y = x+y

First gives diffe

10条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 02:03

    It is explained in the docs in the section entitled "Evaluation order":

    ... while evaluating an assignment, the right-hand side is evaluated before the left-hand side.

提交回复
热议问题