用生成器做斐波那契数列

def f(max):
    n, a, b = 0, 0, 1
    while n <= max:
        yield b
        a, b = b, a + b
        n += 1
    yield 'done'


for i in f(5):
    print(i)
原文地址:https://www.cnblogs.com/xusuns/p/8477639.html