For loop in Python is used for sequential traversal. The Python for loop starts with a keyword “for” followed by an arbitrary variable name, which will hold the values of the following sequence object, which is stepped through.

Python For Loop

Python For Loop is used to iterate over the sequence either the list, a tuple, a dictionary, a set, or the string. It can iterate over the elements of any sequence, such as a list.  Loop continues until we reach the last element in the sequence.

The body of for loop is separated from the rest of the code using indentation. The for loops are traditionally used when you have a block of code in which you want to repeat a fixed number of times.

The general syntax looks like the following code.

for <variable> in <sequence>:
    <statements>

#python #python for loop

Python For Loop: How To Use For Loop In Python
3.80 GEEK