Python range() Function Explained

The range function is used to generate an iterable object containing a sequence of numbers within a specified range, commonly used to control the number of iterations in a loop. Its syntax is:

range(start, stop, step)
  1. Default value for start is 0.
  2. Stop: The ending value (not inclusive), must be specified.
  3. step: the default value is 1.

For example:

for i in range(1, 10, 2):
    print(i)

The output result is:

1
3
5
7
9
bannerAds