Skip to main content

Python Iterators

Body

In this tutorial you will learn:

  • Iterators
  • Iterators in Python
  • Developing your own Iterator

Iterator

We use iterator when we want to go through all elements of collection. It doesn’t need a specific collection or data type, it works irrespective of implementation.

Iterators in Python

Iterator is an object in Python it implements the iterator protocol. A protocol is something that defines some methods and any class implementing that protocol must implement those methods. In Python the iterator protocol requires two fuctions to be implemented one is the __iter__ function

Add new comment

Screenshot