Generators Questions and Answers
Practice ModeShowing 10 of 25 questions
Q21
Can you reset a generator to its initial state?
Answer: Option A
Explanation: Generators cannot be reset; once exhausted, you need to create a new generator instance.
Q22
What is a common use case for generators?
Answer: Option A
Explanation: Generators are ideal for processing large files or data streams where loading everything into memory is impractical.
Q23
What happens if you try to use a generator after it's exhausted?
Answer: Option A
Explanation: Once a generator is exhausted, calling next() on it will always raise StopIteration exception.
Q24
Can generator functions have return statements?
Answer: Option A
Explanation: Generator functions can have return statements, which will raise StopIteration when encountered during execution.
Q25
What is the performance benefit of generators?
Answer: Option A
Explanation: Generators save memory by generating values on-the-fly and allow pipelining of data processing operations.