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.

CategoryBuilt-in Functions
KindBuilt-in Function
Python Versionall

📝 Syntax

range(stop)
range(start, stop[, step])

⚙️ Parameters

stop RequiredThe end value (exclusive); required.
start OptionalThe start value (inclusive); defaults to 0.(Default:0)
step OptionalThe step; defaults to 1; must not be 0.(Default:1)

Returns:An immutable range object of integers; iterable, sized, and indexable.

💥 Raises

▶ 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]
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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏