Iterators
An iterator supplies successive values through next and signals completion with StopIteration. A container can be iterable without being its own iterator.
Understand the idea
iter asks an iterable for an iterator. A list can create fresh independent iterators, while many stream objects and generators are consumed as they are read. for handles the stop signal for you. A default argument to next can make exhaustion a normal value instead of an exception when that suits the operation.
Where to try it
Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.
A worked example
values = iter(["Mira", "Dev"])
print(next(values))
print(next(values))
print(next(values, "Finished"))
Read the result
The outputs are Mira, Dev, and Finished. The final call uses its exhaustion fallback.
Try one change
Create two iterators from one list and show that advancing one does not advance the other.