Practice mode Python

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.