最佳答案
这两个程序并不等同。等号 (=
) 的右侧一起计算。
正在做:
a=b
b=a+b
不同于:
a,b = b,a+b
这实际上等同于:
c = a
a = b
b = b + c
您的示例实际上包含在 Python documentation 中:
The first line contains a multiple assignment: the variables a and b simultaneously get the new values 0 and 1. On the last line this is used again, demonstrating that the expressions on the right-hand side are all evaluated first before any of the assignments take place. The right-hand side expressions are evaluated from the left to the right.
关于python - python中的变量赋值查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44766013/