Tag Archives: Python

The yield keyword in Python

An iterable is an object of a class that has an iter() method to return an iterator.
The for statement calls iter()

An iterator is an object that defines a method next().
When there are no elements left, next() raises StopIteration.

A generator is a function that acts like an iterator by returning elements with yield.