← Quiz: Iterators and Generators: all 10 questions
Quiz: Iterators and Generators · Question 3 of 10
Which exception tells a for loop that an iterator has no more values?
Which exception tells a for loop that an iterator has no more values?
- A.IndexError
- B.ValueError
- C.StopIteration
- D.EOFError
Answer & explanation
Correct answer: StopIteration
next() raises StopIteration, and the for loop catches it and stops.
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 →