Generator Example - Infinite Fibonacci Series

Question

Infinite fibonacci series using generators.

Solution

def fibonacci():
    a, b = 0, 1
    while True:
        yield a
        a, b = b, a+b


for number in fibonacci():
    print number
Run this
Comments by Disqus