Sahaj.blogs

Day page

16 Oct 2023

Study

Python · Iterators

The iterator protocol behind every for loop: iter(), next(), StopIteration, and writing an iterator class.

  • A for loop calls iter() once, then next() repeatedly until StopIteration.
  • An iterable gives you iterators; an iterator is used up after one pass.

Read the post →