[python] generator implements Fibonacci

# generator function, as long as there is a yield keyword in the function 
def gen_func():
    yield 1
    yield 2
    yield 3

def fib(index):
    if index <= 2:
        return 1
    else:
        return fib(index-1) + fib(index-2)

def fib2(index):
    re_list = []
    n,a,b = 0,0,1
    while n<index:
        re_list.append(b)
        a,b = b, a+b
        n += 1
    return re_list

def gen_fib(index):
    n,a,b = 0,0,1
    while n<index:
        yield b
        a,b = b, a+b
        n += 1

for data in gen_fib(10):
    print (data)
# print (gen_fib(10))
# Fibonacci 0 1 1 2 3 5 8
# lazy evaluation Delay evaluation provides a possible 

def func():
    return 1

if __name__ == "__main__":
    # generator object, which is generated when python compiles bytecode, gen = gen_func()for value in gen:
        print (value)
    # re = func()
    # pass