range() Function in Python

The range() function generates a sequence of numbers and is commonly used with for loops.

🔢 range() saves memory and improves performance.

range(stop)

for i in range(5):
    print(i)

range(start, stop)

for i in range(1, 6):
    print(i)

range(start, stop, step)

for i in range(2, 11, 2):
    print(i)

Practice

  1. Print numbers from 10 to 1
  2. Print multiples of 5 up to 50