这是因为Python的元组解包.在第一个中,Python收集右侧的值,使它们成为元组,然后将元组的值分别分配给左侧的名称.所以,如果a == 1且b == 2:
a, b = b, a + b => a, b = (2, 3) => a = 2, b = 3
但在第二个例子中,它是正常的分配:
a = b => a = 2 b = a + b => b = 4