Iterators & Generators

Iterables are things you can loop over.

Iterators are the agent that does the looping over iterables.

Also, just to make things confusing (really it's to make our lives easier as Pytonistas), iterators are also iterables and all iterators are their own iterators.

Generators are just one flavor of iterator: they're the most common type of iterator you'll usually create yourself.

If you want to make a lazy iterable, one that computes values as you loop over it, generators are usually the tool you'll use.

Related Topics

Recommended Resources