Basic syntax of a for loop in Python
In Python, a for loop is used to iterate over a sequence of elements. The basic syntax of a for loop in Python is as follows:
for variable in sequence:
# code block to be executed
The variable is a placeholder that represents each element in the sequence. The sequence can be a list, a string, a range of numbers, or any other iterable object.
Let’s take a look at some examples to understand how to use a for loop in Python.