User Tools

Site Tools


python:fibonacci

Fibonacci implementation

26.01.2016

A good example of iterators and generators.

def fibonacci(n):
    a,b  = 0, 1
    while n:
        yield a
        a, b = b, a + b
        n -= 1
 
for x in fibonacci(10):
    print(x,)

Check the live code here.

python/fibonacci.txt · Last modified: 2016/01/26 05:34 by admin