Iterable

In Python, an iterable is an object that can return its elements one at a time, allowing you to loop over it using a for loop or any other iteration tool. Technically, an iterable must implement the .__iter__() special method which returns an iterator, or implement .__getitem__() to support indexing.

Common built-in iterables include lists, tuples, strings, dictionaries, and sets.

Iterables form the backbone of Python’s for loops and can be used in list comprehensions, generator expressions, and with the in operator. Unlike iterators, iterables can be traversed multiple times and typically represent a sequence or collection of data that exists in memory.

Python Iterable Example

Here’s an example that demonstrates how to iterate over a list, which is a common type of iterable:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

You must own this product to join the conversation.