Search⌘ K
AI Features

Iterables in Python

Understand the concept of iterables and how Python uses the iter function to create iterators. Learn how the next function retrieves items until the StopIteration exception signals completion. This lesson clarifies iteration mechanics behind Python's for loops and other iteration contexts.

What is iterable?

Any object from which the iter built-in function can acquire an iterator is called iterable.

All sequences are iterable.

💡 Python obtains iterators from iterables.

Mostly, we iterate via a for loop. For example:

Python 3.10.4
message = 'Hello'
for letter in message:
print(letter)

It will ...