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()
In [ ]: