Skip to main content

Python

Iterators & Generators in Python

·474 words·3 mins
This post aims to describe the basic mechanisms behind iterators and generators. Iterator protocol # As in many programming languages, Python allows you to iterate over a collection. The iteration mechanism is often useful when we need to scan a sequence, an operation that is very common in programming. In Python, the iterator protocol involves two components: an iterable and an iterator.