The range() function in Python has up to three parameters:
-
start (optional): This is the starting value of the sequence. If not provided, it defaults to 0.
-
stop: This is the end value of the sequence (exclusive). The sequence will generate numbers up to, but not including, this value.
-
step (optional): This is the increment (or decrement) between each number in the sequence. If not provided, it defaults to 1. If you want a decreasing sequence, you can provide a negative value for this parameter.
Syntax
range(start, stop, step)
Examples
range(5)generates numbers from 0 to 4.range(1, 5)generates numbers from 1 to 4.range(1, 10, 2)generates numbers from 1 to 9, incrementing by 2 (1, 3, 5, 7, 9).range(10, 0, -1)generates numbers from 10 to 1, decrementing by 1.
