Tag Archives: Python

The yield keyword in Python

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

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

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