as more formal definitionfigure - sketches this full iteration protocolused by every iteration tool in pythonand supported by wide variety of object types it' really based on two objectsused in two distinct steps by iteration toolsthe iterable object you request iteration forwhose __iter__ is run by iter the iterator object returned by the iterable that actually produces values during the iterationwhose __next__ is run by next and raises stopiteration when finished producing results these steps are orchestrated automatically by iteration tools in most casesbut it helps to understand these two objectsroles for examplein some cases these two objects are the same when only single scan is supported ( files)and the iterator object is often temporaryused internally by the iteration tool moreoversome objects are both an iteration context tool (they iterateand an iterable object (their results are iterable)--including ' generator expressionsand map and zip in python as we'll see aheadmore tools become iterables in -including mapziprangeand some dictionary methods--to avoid constructing result lists in memory all at once figure - the python iteration protocolused by for loopscomprehensionsmapsand moreand supported by fileslistsdictionaries' generatorsand more some objects are both iteration context and iterable objectsuch as generator expressions and ' flavors of some tools (such as map and zipsome objects are both iterable and iteratorreturning themselves for the iter(callwhich is then no-op in actual codethe protocol' first step becomes obvious if we look at how for loops internally process built-in sequence types such as listsl [ iter(li __next__( iterations and comprehensions obtain an iterator object from an iterable call iterator' next to advance to next item