Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 11)
11.
How can you stop the execution of a generator prematurely?
Raise a StopIteration exception
Use the break statement
Call the stop() method on the generator
Return from the generator function
Answer: Option
Explanation:
To stop the execution of a generator prematurely, you can use the break statement within the generator function. This will exit the generator's loop.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.