Which methods make an object an iterator?
Options
__len__and__getitem__, which allow indexing and length__iter__and__next__, withStopIterationraised at the end (Correct option)__enter__and__exit__, which handle setup and cleanup__call__and__next__, which allow calling and advancing
Answer
__iter__ and __next__ (raising StopIteration at the end)
Why
An iterator is an object that gives you the next value each time you call next() on it.
It needs __next__ (return the next value, or raise StopIteration when there are no more) and __iter__ (return itself).
A for loop calls these methods for you behind the scenes.
Remember
Iterator = __iter__ + __next__.