Howto_Generators: 28/May/2016

In [2]:
def fibonacci(number):
    """
    An example for generator function using yield.
    """
    result = 0
    base = 1
    while (result <= number):
        """ yield : sort of jump to parent calling function todo some processing 
        there and return back to the called function and resume the code execution.
        """
        yield result
        
        n = result + base
        result = base
        base = n
        
def main():
    for x in fibonacci(27):
        print x
    
if __name__ == '__main__':
    main()


0
1
1
2
3
5
8
13
21

In [ ]: