In this tutorial, you will learn how to iterate over a list using For loop statement, with the help of example programs.
Python – List For Loop
To iterate over elements of a Python List using For Loop statement, use the list as iterable in For loop syntax.
The syntax to iterate over Python List using For Loop, and print that element is given below.
for element in mylist :
print(element)
where mylist
is the Python List, and element
is the element with read only access during each iteration. Meaning, you cannot change the value of elements in the list, using for loop.
Examples
In the following programs, we take a list of elements, and then use For loop statement to iterate over the elements in the list.
1. Iterate over list of numbers using For loop
In this example, we will take a Python List, and iterate over all the elements of this list using for loop.
Python Program
list_1 = [4, 52, 6, 9, 21]
for element in list_1 :
print(element)
Output
4
52
6
9
21
Reference tutorials for the above program
2. Iterate over list of strings using For loop
In this example, we will take a Python List of strings, and iterate over all the elements of list using for loop.
Python Program
list_1 = ["Nemo", "Arc", "Gary"]
for element in list_1 :
print(element)
Output
Nemo
Arc
Gary
Conclusion
In this Python Tutorial, we learned how to iterate over elements of a Python List using For Loop statement.