How to Make a Sequence of Numbers in Python with range
When you need the numbers 0 to 4, or 1 to 5, or every third number up to 10, Python's range makes them for you. It's what for loops usually count with. This guide makes three sequences and turns each into a list to show it, with real output from Python 3.15.2.
Syntax
range(<stop>)
range(<start>, <stop>)
range(<start>, <stop>, <step>)
| Part | What it means |
|---|---|
<start> | The first number. Without it, 0 |
<stop> | Where the sequence ends. This number itself is not included |
<step> | The gap between numbers. Without it, 1; a negative step counts down |
The built-in types reference: "The range type represents an immutable sequence of numbers and is commonly used for looping a specific number of times in for loops."
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
list(...) turns each range into a list, so print shows every number in it.
print(list(range(5)))
print(list(range(1, 6)))
print(list(range(0, 10, 3)))

Step 2: Run It
uv run python count.py
[0, 1, 2, 3, 4]
[1, 2, 3, 4, 5]
[0, 3, 6, 9]
![The script's output in a terminal: [0, 1, 2, 3, 4], [1, 2, 3, 4, 5] and [0, 3, 6, 9].](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/programming/python/2026/python-range-02-output.webp)
range(5) stops before 5, so to reach 5 the second call ends at 6. The step of 3 gave 0, 3, 6, 9.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Expecting the stop number in the result | range(1, 5) ends at 4 | Use one more than the last number you want |
| Printing a range directly | print(range(5)) printed range(0, 5), not the numbers | list(range(5)), or loop over it with for |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
TypeError: 'float' object cannot be interpreted as an integer | A decimal number such as range(0.5) | range takes whole numbers only; use int(...) |
FAQ
Can range count down?
Yes, with a negative step: list(range(5, 0, -1)) gave [5, 4, 3, 2, 1].
Does range make all the numbers at once?
No. The reference says a range "only stores the start, stop and step values, calculating individual items and subranges as needed", which is why print shows range(0, 5) instead of a list.
Conclusion
range(5), range(1, 6) and range(0, 10, 3) gave [0, 1, 2, 3, 4], [1, 2, 3, 4, 5] and [0, 3, 6, 9]: start at the first number, step by the step, and stop before the stop.
Additional Resources
- Ranges — the range type.
- The range() function — the tutorial, with loops.
