Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM
28-Sep-2025The
range()function in Python is a built-in way to generate a sequence of numbers. You often see it used in loops (likefor) or anytime you need a sequence of integers without storing them in a list up front.Basic Syntax
start→ The number to begin at (default =0).stop→ The number to end at (this number is excluded).step→ The increment (default =1). Can be negative for counting backwards.Examples
Simplest usage (only
stop):Output:
(It starts at
0, ends before5.)With
startandstop:Output:
With
step:Output:
Counting backwards:
Output:
Key Details
range()does not create a list; it creates a special object (a range object) that generates numbers on demand (memory efficient).If you need the actual list, wrap it with
list():