Python in 60 seconds: Iterators, Iterables and Iteration

Adewale I. Salami
1 min readSep 21, 2021

Hello there!

I am starting this series on useful bits of python that can be digested in 60 seconds.

This series will introduce very quick and precise concepts in python.

What are Iterables, Iterators and Iteration?

Iterables are objects that implements the python __iter__ method.

Iterators are objects that implement both the __iter__ and __next__ methods.

Iteration is transversing a data container.

You can return an Iterator from an Iterable by calling the python iter() method on it.

Let’s take some examples:

name = [‘Rose’, ‘John’]

From the above, name is an iterable. We can make it an Iterator by calling the iter() function on it like below:

it = iter(name)

To get each data in the Iterator, we call the next() function on it like below:

next(it)

>>> Rose

next(it)

>>> John

You can implement an Iterator with the iter() and the next() methods.

Thank you for reading and God bless!!!

--

--

Adewale I. Salami
0 Followers

I love Python. I do Django, AWS, Htmx, Bootstrap 5, JS. Learning Web Scrapping, AI and ML