Nov-07-2023, 06:27 AM
hi
after running the code:
what is the reason for this? plz, explain.
thanks
after running the code:
def gen(): for i in range(3): yield i*i return g1=gen() for i in g1(): print(i)the below error will be shown in the output:
Error:Traceback (most recent call last):
File "<pyshell#36>", line 1, in <module>
for i in g1():
TypeError: 'generator' object is not callable
but if i use gen()itself , namely:for i in gen(): print(i)then the output will be:
Output:0
1
4
or if the code will be changed to: g1=gen() for i in g1: print(i)then the last true output is displayed again.
what is the reason for this? plz, explain.
thanks