Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 73)
73.
How does the generator.throw(GeneratorExit) method differ from generator.close()?
They are equivalent in functionality
generator.throw(GeneratorExit) raises a GeneratorExit exception in the generator, while generator.close() terminates the generator
generator.close() raises a GeneratorExit exception, while generator.throw(GeneratorExit) terminates the generator
generator.throw(GeneratorExit) and generator.close() are not valid methods
Answer: Option
Explanation:
generator.throw(GeneratorExit) raises a GeneratorExit exception in the generator, indicating that the generator should be closed. generator.close() terminates the generator without raising an exception.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.