Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 48)
48.
What happens if a generator function contains both yield and return statements?
It raises a GeneratorExit exception
It raises a StopIteration exception
It returns the specified value and stops the generator
It is a syntax error; yield and return cannot be used together
Answer: Option
Explanation:
If a generator function contains both yield and return statements, it returns the specified value and stops the generator.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.