Skip to content

iteration

In Python, iteration is the process of repeatedly accessing the items of an iterable, such as a sequence or collection, one at a time. This is typically done with for loops, which get an iterator from the iterable behind the scenes. That’s why iteration also works over objects that don’t hold all their items in memory, such as generators and file objects.

Python provides powerful tools for iteration, allowing you to loop over items in data structures like lists, tuples, dictionaries, and more.

Iteration is a fundamental concept in programming. It enables you to automate repetitive tasks and work efficiently with data collections.

Example

Here’s a quick example of iteration using a for loop to iterate over a list of numbers and print each one:

Language: Python
>>> numbers = [1, 2, 3, 4, 5]
>>> for number in numbers:
...     print(number)
...
1
2
3
4
5

In this example, the for loop iterates over each item in the numbers list and prints it to your screen.

Python for Loops: The Pythonic Way

Tutorial

Python for Loops: The Pythonic Way

Learn how to use Python for loops to iterate over lists, tuples, strings, and dictionaries with Pythonic looping techniques.

intermediate best-practices python

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Sept. 18, 2026