python多个变量赋值

a, b = 3, 4
c, d = 3, 4

a, b = b, a + b
c = d
d = c + d
print(a, b, c, d)

输出:

4 7 4 8

因为a, b和b, a + b都是元祖(tuple)

先计算(b, a + b)的元祖为(4, 7)然后将该元祖赋值给(a, b)

其等于以下代码:

a, b = 3, 4
c = (b, a + b)
a, b = c

  

转载于:https://www.cnblogs.com/shiyongqing/p/6806776.html

你可能感兴趣的:(python多个变量赋值)