python-small-examples

@author jackzhenguo
@desc 
@date 2019/11/23

126 斐波那契数列前n项

def fibonacci(n):
    a, b = 1, 1
    for _ in range(n):
        yield a
        a, b = b, a + b


list(fibonacci(5))  # [1, 1, 2, 3, 5]
[上一个例子](/python-small-examples/md/125.html) [下一个例子](/python-small-examples/md/127.html)