python-small-examples/md/126.md at master · data-python/python-small-examples

Skip to content

Navigation Menu

Sign in

Appearance settings

Latest commit

File metadata and controls

18 lines (14 loc) · 247 Bytes

@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]