Python Tutorial

Python Interators Explained With Examples

What are Iterators in Python?

An iterator is a collection of values that may be counted. It is a type of object that can be iterated over, which means you can go over all of the data. You can also call it a Python object that implements the iterator protocol, which includes the methods __iter__() and __next__ ().

Code:

my_tuple = ("a", "b", "c")

my_it = iter(my_tuple)

print(next(my_it))

print(next(my_it))

print(next(my_it))

Output:

a
b
c
Did you find this article helpful?