gpt4 book ai didi

python - 速记代码和斐波那契数列

转载 作者:太空狗 更新时间:2023-10-30 02:44:02 25 4
gpt4 key购买 nike

<分区>

我找到了这样的斐波那契数列示例:

def fib(n):
a, b = 0, 1
while b < n:
print (b)
a, b = b, a+b

fib(20)

所以这是我不明白的:

a, b = 0, 1 # is just a shortcut for writing
a = 0
b = 1

对吗?

现在,遵循相同的逻辑

a, b = b, a+b #should be the same as writing
a = b
b = a+b

但这不是因为如果我那样写,输出是不同的。我很难理解为什么。有什么想法吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com