Which exception does an iterator raise from __next__ to signal that it has no more items?
Correct answer D. StopIteration
Explanation
The iterator protocol requires __iter__ to return the iterator and __next__ to return the next item or raise StopIteration when exhausted. A for loop catches StopIteration silently and ends. IndexError is used by sequence indexing, EOFError by input(), and IteratorEnd does not exist.
Answer checked How we write and check questions
Discussion