CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day13/generator2.py
Views: 729
1
"""
2
生成器 - 使用yield关键字
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-21
7
"""
8
9
10
def fib(num):
11
n, a, b = 0, 0, 1
12
while n < num:
13
yield b
14
a, b = b, a + b
15
n += 1
16
17
18
for x in fib(20):
19
print(x)
20
21