iteration
In Python, iteration is the process of repeatedly accessing elements from a sequence or collection, one at a time. This is typically done with for
loops.
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 July 4, 2025