python for loop - top 10 examples to get started now
Updated Jun 2026 · originally published Jan 2023 · Tested on Linux, Unix
A for loop in Python is used to repeat a block of code for a certain number of times or until a certain condition is met. for loop is used to iterate over a sequence of elements such as a list, tuple, string, ,range or dictionary.
The general syntax of a for loop in Python is:
for variable in sequence:
code to be executed
The sequence can be any iterable object like a list, tuple, string, etc.
The variable takes on the values in the sequence one by one with each iteration and execute the code to process the variable, as in simplest case just print the variable value in each pass.