...

/

Usage of the for Loop

Usage of the for Loop

Learn how to use the for loop in a Python program.

The for loop can be used in these two situations:

  • Repeating a set of statements a finite number of times.
  • Iterating through a string, list, tuple, set, or dictionary.

First usage of the for loop

To repeat a set of statements a finite number of times, a built-in range() function is used.

The range() function generates a sequence of integers. For ...