range()
IterableReturns an immutable sequence of numbers. The most common way to generate number sequences.
Signature
range(stop) | range(start, stop, step)
Returns
rangeExample
for i in range(5):
print(i) # 0, 1, 2, 3, 4
nums = list(range(0, 20, 3))
print(nums) # [0, 3, 6, 9, 12, 15, 18]About range()
range is a Python iterable function with the signature range(stop) | range(start, stop, step). Returns an immutable sequence of numbers. The most common way to generate number sequences. It returns a value of type range.
Python provides a rich set of built-in functions and standard library modules that cover common programming tasks. Understanding these functions helps you write more idiomatic, efficient Python code. The rangefunction is commonly used in data processing, web development, scripting, and automation tasks.
When working with range(), consider edge cases like empty inputs, None values, and type mismatches. Python's duck typing means many built-in functions work with any object that implements the required protocol (e.g., __len__ for len(), __iter__ for iteration). This flexibility is a key strength of Python's design philosophy.