iteration
In Python, iteration refers to the process of executing a block of code repeatedly. This is typically done with loops such as for
and while
.
When you iterate over a data collection, you go through each item one by one. 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
In this tutorial, you'll learn all about the Python for loop. You'll learn how to use this loop to iterate over built-in data types, such as lists, tuples, strings, and dictionaries. You'll also explore some Pythonic looping techniques and much more.
For additional information on related topics, take a look at the following resources:
By Leodanis Pozo Ramos • Updated May 6, 2025