Worked Examples · Example 6.4
Q.Demonstration of the range() function with different parameter combinations at the interpreter: list(range(10)) with start and step not specified; list(range(2, 10)) with default step value 1; list(range(0, 30, 5)) with step value 5; list(range(0, -9, -1)) with step value -1 generating a decreasing sequence.
Punjab PsebTextbookSubjective· 2mImportance★★★★★est
18% · 7/39 Questions
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 four calls demonstrate range()'s parameter rules — default start 0 and step 1, the stop value always excluded, and a negative step producing a decreasing sequence.
The idea. range(start, stop, step) generates integers lazily; passing it to list() materialises the sequence so the interpreter shows it. The four demonstrations cover every parameter combination:
>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(2, 10))
[2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(0, 30, 5))
[0, 5, 10, 15, 20, 25]
>>> list(range(0, -9, -1))
[0, -1, -2, -3, -4, -5, -6, -7, -8]
What each call shows
| Call | start | stop | step | Sequence | Rule illustrated |
|---|---|---|---|---|---|
| range(10) | 0 (default) | 10 | 1 (default) | 0…9 | one argument = stop; start/step default |
| range(2, 10) | 2 | 10 | 1 (default) | 2…9 | two arguments = start, stop |
| range(0, 30, 5) | 0 | 30 | 5 | 0, 5, 10, 15, 20, 25 | custom step; 30 itself excluded |
| range(0, -9, -1) | 0 | -9 | -1 | 0 down to -8 | negative step counts DOWN, stops before -9 |
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.