What is for loop

A for loop in Python is used to iterate over a sequence (like a list, tuple, dictionary, set, or string) and execute a block of code multiple times.

Here is the syntax

for <loop_variable> in <values>:

   <do something>

If you want to loop N times, you replace the <values> with the expression range(N) , where N is an integer number. range is a special procedure in Python.

The expression range(N) yields the sequence 0, 1, 2, 3, … N – 1


You have completed 0% of the lesson
0%