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:
>>> 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.
Related Resources
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.
For additional information on related topics, take a look at the following resources:
- Python while Loops: Repeating Tasks Conditionally (Tutorial)
- Efficient Iterations With Python Iterators and Iterables (Course)
- How to Iterate Through a Dictionary in Python (Tutorial)
- Using the Python zip() Function for Parallel Iteration (Tutorial)
- For Loops in Python (Definite Iteration) (Course)
- Python for Loops: The Pythonic Way (Quiz)
- Mastering While Loops (Course)
- Python while Loops: Repeating Tasks Conditionally (Quiz)
- Python Dictionary Iteration: Advanced Tips & Tricks (Course)
- Python Dictionary Iteration (Quiz)
- Parallel Iteration With Python's zip() Function (Course)
- Using the Python zip() Function for Parallel Iteration (Quiz)
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