标签:斐波那契数列 代码 color ext 斐波那契 generator col yield def
下面的小代码是应用斐波那契数列小代码,展示生成器作用
def fib(n): before,after = 0,1 for i in range(n): yield before before,after = after,before + after g = fib(10) print(g) for i in range(10): print(next(g))
运行结果如下:
<generator object fib at 0x7f923958bf10>
0
1
1
2
3
5
8
13
21
34
标签:斐波那契数列 代码 color ext 斐波那契 generator col yield def
原文地址:https://www.cnblogs.com/iceberg710815/p/11944406.html