更新
This commit is contained in:
21
Python-100-Days/Day01-15/Day13/generator2.py
Normal file
21
Python-100-Days/Day01-15/Day13/generator2.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""
|
||||
|
||||
生成器 - 使用yield关键字
|
||||
|
||||
Version: 0.1
|
||||
Author: 骆昊
|
||||
Date: 2018-03-21
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def fib(num):
|
||||
n, a, b = 0, 0, 1
|
||||
while n < num:
|
||||
yield b
|
||||
a, b = b, a + b
|
||||
n += 1
|
||||
|
||||
|
||||
for x in fib(20):
|
||||
print(x)
|
||||
Reference in New Issue
Block a user