Python笔记-斐波那契

def fiboonacci(n):
    num1 = num2 = 1
    count = 0
    while count <= n - 2:
        num1,num2 = num2,num1 + num2
        count += 1
        yield num1

F = fiboonacci(12)  # 此时并不会调用函数
for i in F:
    print(i)

结果

1
2
3
5
8
13
21
34
55
89
144

Process finished with exit code 0
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页