1. 程式人生 > >python用生成器生成裴波那契數列

python用生成器生成裴波那契數列

#_*_coding:utf-8_*_

def f():
    a,b=1,1
    while True:
        yield a
        a,b = b,a+b
a = f()
for i in range(10):
    print(a.__next__(),end =   ' ')

1 1 2 3 5 8 13 21 34 55