range() Sequence of integers
Last updated: 2026-09-22
range() Sequence of integers
range(stop) or range(start, stop[, step]) returns an immutable integer sequence; commonly used in for-loops.
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | all |
📝 Syntax
range(stop)
range(start, stop[, step])
⚙️ Parameters
| stop Required | The end value (exclusive); required. |
|---|---|
| start Optional | The start value (inclusive); defaults to 0.(Default:0) |
| step Optional | The step; defaults to 1; must not be 0.(Default:1) |
Returns:An immutable range object of integers; iterable, sized, and indexable.
💥 Raises
TypeError— Raised when an argument is not an integer (or lacks __index__).ValueError— Raised when step is 0.
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
[0, 1, 2, 3, 4]
[1, 3, 5, 7, 9]
🏷️ Related Built-in Functions
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhy is list(range(5)) [0,1,2,3,4] instead of going up to 5?
Arange is a half-open interval — stop is not included; to get 1-5 use range(1, 6).
QWhat does range(1, 10, 2) produce?
AIt produces 1, 3, 5, 7, 9. step is the stride; a step of 0 raises ValueError: range() arg 3 must not be zero.
QIs range a list? Does it use much memory?
ANo, it is a lazy sequence object storing only start/stop/step, so range(10**9) barely uses memory; yet it supports len(), indexing, and the in operator.
QHow do I iterate in reverse?
AUse a negative step: range(10, 0, -1) produces 10 down to 1, and range(4, -1, -1) produces 4 down to 0.