Generating function:
def geraQuadrados(n):
for i in range(n):
yield i**2
for i in geraQuadrados(5):
print(i)
No generating function:
def novosQuadrados(n):
l = []
for i in range(n):
l.append(i**2)
return l
for i in novosQuadrados(5):
print(i)
The codes with the use of generating function and without the generating function have the same output. Is there any advantage in using generator / yield function?
I still find the yield clause confusing!