← Quiz: Iterators and Generators: all 10 questions
Quiz: Iterators and Generators · Question 5 of 10
What happens when you call a generator function?
What happens when you call a generator function?
- A.Its body runs to the end immediately
- B.It returns the first yielded value
- C.It returns a generator object; the body runs only when values are requested
- D.It raises StopIteration
Answer & explanation
Correct answer: It returns a generator object; the body runs only when values are requested
The body starts running at the first next() call.
Can you get the rest right without peeking?
Take the timed Quiz: Iterators and Generators quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →