The range() function in Python generates a sequence of numbers and is commonly used in loops. It takes up to three arguments:
1. range(stop): Generates numbers from 0 up to, but not including, stop.
range(5) # Output: 0, 1, 2, 3, 4
2. range(start, stop): Generates numbers from start to stop (exclusive).
range(2, 6) # Output: 2, 3, 4, 5
3. range(start, stop, step): Generates numbers from start to stop, incrementing by step.
range(1, 10, 2) # Output: 1, 3, 5, 7, 9
range() produces an immutable sequence, which can be converted to a list if needed. It is memory efficient, as it generates numbers on demand.