Iterable and Iterator in Python

Yang Zhou
TechToFreedom
Published in
4 min readMay 28, 2020

--

Iterable and Iterator in Python
Photo by Claire Satera on Unsplash

Introduction

Iterable and Iterator are important concepts of Python. However, sometimes it could be confusing. This post will dive into these concepts and help you totally understand them.

Iterable VS Iterator

First of all, we should know that Iterable and Iterator are different. To be exact, Iterator is a subclass of Iterable. An Iterable object, such as list ,tuple , dict , set and str , can produce an Iterator by iter() function. For example:

Intuitively, any objects that can be iterated by the for...in... loop is an Iterable object. An Iterator is also an Iterable since it’s the subclass of Iterable. We can check it using isinstance() function:

Let’s have a look at the Python 3.6 typing.py source code:

--

--