Q.
list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
#start value is given as 2
list(range(2, 10))
[2, 3, 4, 5, 6, 7, 8, 9]
#step value is 5 and start value is 0
list(range(0, 30, 5))
[0, 5, 10, 15, 20, 25]
#step value is -1. Hence, decreasing
#sequence is generated
list(range(0, -9, -1))
[0, -1, -2, -3, -4, -5, -6, -7, -8]
list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
#start value is given as 2
list(range(2, 10))
[2, 3, 4, 5, 6, 7, 8, 9]
#step value is 5 and start value is 0
list(range(0, 30, 5))
[0, 5, 10, 15, 20, 25]
#step value is -1. Hence, decreasing
#sequence is generated
list(range(0, -9, -1))
[0, -1, -2, -3, -4, -5, -6, -7, -8]
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →The range() function generates arithmetic sequences; list(range(...)) materializes them as lists with start (inclusive), stop (exclusive), and step parameters.
Why range() matters
Python's range() is the standard tool for generating integer sequences. It takes up to three arguments: range(start, stop, step). Understanding how these parameters interact is essential for loops, list generation, and any task requiring a predictable numeric progression.
The key insight: range() is half-open on the right. It includes start but excludes stop. The sequence increments by step until it would meet or exceed stop (for positive step) or fall below it (for negative step).
Parameter rules
| Form | Meaning | Example |
|---|---|---|
range(stop) | Start at 0, step by 1, stop before stop | range(10) → 0, 1, …, 9 |
range(start, stop) | Begin at start, step by 1, stop before stop | range(2, 10) → 2, 3, …, 9 |
range(start, stop, step) | Begin at start, increment by step, stop before crossing stop | range(0, 30, 5) → 0, 5, 10, 15, 20, 25 |
When step is negative, the sequence decreases. The stop condition reverses: generation continues while the current value is greater than stop.
Trace of the given examples
Example 1: list(range(10))
- Only
stopis given → start defaults to 0, step defaults to 1. - Sequence: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (stops before 10).
Example 2: list(range(2, 10))
start = 2,stop = 10, step defaults to 1.- Sequence: 2, 3, 4, 5, 6, 7, 8, 9 (stops before 10).
Example 3: list(range(0, 30, 5))
start = 0,stop = 30,step = 5.- Sequence: 0, 5, 10, 15, 20, 25 (next would be 30, which equals
stop→ excluded).
Example 4: list(range(0, -9, -1))
start = 0,stop = -9,step = -1.- Decreasing sequence: 0, -1, -2, -3, -4, -5, -6, -7, -8 (next would be -9, which equals
stop→ excluded).
A common mistake: expecting range(10) to include 10. It does not. The upper bound is always exclusive. If you need 1 through 10, write range(1, 11). …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.