python generater yeild
#list
L = [x * x for x in range(10)]
#generrater
g = (x * x for x in range(10))
g
Out[4]: <generator object <genexpr> at 0x7f3d143048e0>
L
Out[5]: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
for i in g:
print(i)
1
4
9
16
25
36
49
64
81
def fib(max):
n, a, b = 0, 0, 1
while n < max:
yield b
a, b = b, a + b
n = n + 1
return 'done'
c=fib(6)
for k in c :
print(k)
1
1
2
3
5
8