Run

Fibonacci series in Python

Print the first n Fibonacci numbers with a generator. Press Run to try it, then change the code and run it again.

main.py

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

print(", ".join(str(x) for x in fibonacci(10)))
Output

Press Run to see the output.

More Python examples

Open the full Python online compiler →