无法理解python中的逗号分隔变量

时间:2019-07-12 19:45:08

标签: python python-3.x

如果

a, b = 0, 1

表示

a = 0 
b = 1 

然后

a, b = b , a + b

应该是

a = b 
b = a + b 

但是如果我在(https://docs.python.org/3/tutorial/controlflow.html#defining-functions)的fib函数中使用了它,它将无法正常工作。有人可以帮助我了解它的工作原理吗?

所以

的输出
def fib(n):
    a, b = 0, 1
    while a < n:
        print(a, end = ' ')
        a = b 
        b = a + b 
    print()

fib(50)

0 1 2 4 8 16 32

0 个答案:

没有答案