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
- Print numbers from 10 to 1
- Print multiples of 5 up to 50