Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 4)
4.
What happens when a generator function encounters the yield keyword?
The function terminates immediately
The value is returned, and the function's state is saved
The function raises an exception
The function restarts from the beginning
Answer: Option
Explanation:
When a generator function encounters the yield keyword, it returns the specified value and saves its state. The next time the generator is called, it resumes execution from where it left off.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.