TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
range object in Python is a built-in, immutable sequence type that represents a mathematical progression of integers. Rather than pre-allocating memory for every integer in the sequence, range computes its values dynamically on demand. This lazy evaluation strategy guarantees an space complexity, meaning a range of ten takes the exact same amount of memory as a range of ten billion.
Syntax
Therange constructor is overloaded and can be instantiated using one, two, or three arguments. All arguments must be integers or objects that implement the __index__() special method.
start(Optional): The inclusive lower bound of the sequence. Defaults to0if omitted.stop(Required): The exclusive upper bound of the sequence. The progression stops before it reaches or exceeds this value.step(Optional): The integer difference between consecutive values. Defaults to1. It can be negative for descending progressions, but it cannot be0(raises aValueError).
Mechanics and Instantiation
When instantiated, therange object calculates the length of the sequence and stores only the start, stop, and step attributes.
Sequence Protocol Implementation
Despite behaving similarly to a generator during iteration,range is a fully realized sequence type. It implements the complete Python sequence protocol (__getitem__, __len__, __contains__, __iter__, and __reversed__).
Because it calculates values mathematically rather than traversing memory, most sequence operations execute in time complexity. For membership testing (in), the __contains__ method evaluates mathematically in time for integers. However, if testing for membership of a non-integer object (such as a custom class with an overloaded __eq__ method), it falls back to an linear search.
Equality and Hashing
Becauserange objects are immutable, they are hashable and can be used as dictionary keys or set elements.
Equality between range objects is evaluated based on the sequence of values they represent, not their strict instantiation arguments. Two range objects are considered equal (==) if they yield the exact same sequence of integers.
Master Python with Deep Grasping Methodology!Learn More





