Python language

Iterator protocol

__iter__ returning an iterator and __next__ returning the next value or raising StopIteration.

Why interviewers ask about it

Distinguish iterable from iterator. A list is iterable and gives a fresh iterator each time; a generator is its own iterator and exhausts once.

This term is part of the free Python Full-Stack interview preparation module - browse the full glossary for every definition.