What Is The Difference Between Normal Function And Generator Function?
I am trying to understand the below methodology, In [26]: def generator(): ....: print 'generator function hits' ....: for i in range(3): ....: yield i
Solution 1:
Because a generator function's body is not executed until you call next
on it.
>>>gen = generator()>>>next(gen)
generator function hits
0
Now on the second next()
call the generator will run again from where it left off:
>>>next(gen)
1
Post a Comment for "What Is The Difference Between Normal Function And Generator Function?"