-
- xrange (
stop )
-
- xrange (
start,
stop[,
step] )
-
This function was very similar to range () , but returns an Xrange object instead of a list. This is a opaque sequence type which yields the same values as the corresponding list, without actually storing them all Simultaneously. The advantage of xrange () over range () is minimal (since xrange () still have to create the value s when asked for them) except when a very large range are used on a memory-starved machine or if all of the range ' s Eleme NTS was never used (such as when the loop was usually terminated with break ). For more information on Xrange objects, see xrange Type and Sequence types-str, Unicode, list, tuple, Bytea Rray, buffer, xrange .
CPython Implementation Detail: xrange () is intended to being simple and fast. Implementations impose restrictions to achieve. The c implementation of Python restricts all arguments to native C longs (' short ' python integers), and also requires that The number of elements fit in a native C long. If a larger range is needed, an alternate version can be crafted using the itertools module: islice (COUNT (STA RT, Step), (stop-start+step-1+2* (step<0))//step).
-
-
—————————————————————————————————————————————
-
-
- xrange (
stop )
-
- xrange (
start,
stop[,
step] )
-
-
This function is similar to the range () function, but returns a Xrange object instead of a list.
Xrange is an opaque array that produces the same values as the corresponding list, but xrange does not store the values. Xrange () has no obvious advantage over range () except for certain situations such as an array that is too large and out of memory, and where frequent termination causes all elements in the array to be inaccessible. This is because when the elements in the array are accessed, xrange () still needs to create them.
For more information about XRange (), see XRange Type and Sequence types-str, Unicode, list, tuple, ByteArray, buffer, XRange.
CPython Implementation Details: in order to make xrange () simple and fast, the compiler will use some strict restrictions to achieve this purpose. CPython restricts all parameters to long and requires that the number of elements not exceed the range of long. If you need a larger array, you can use a more refined model that uses the Circulator (Itertools):
-
-
islice (Start, Step), (stop-start+step-1+2* (step<0))//step).
-
-
2,range ():
-
-
- Range (
stop )
-
- Range (
start,
stop[,
step] )
-
-
This is a versatile function to create lists containing arithmetic progressions. It is the most often used in for loops. The arguments must be plain integers. If The step argument is omitted, it defaults to 1 . If the start argument is omitted, it defaults to 0 . The full form returns a list of plain integers [start, start + step, start + 2 * step, ...] . If step is positive, the last element was the largest start + I * step less than stop ; If step is negative, the last element is the smallest start + i * step greater than stop . step must not
being zero (or else valueerror is raised).
-
-
Example:
>>>
>>> range [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> range (1, one) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]>>> R Ange (0, 5) [0, 5, ten,, 25]>>> range (0,, 3) [0, 3, 6, 9]>>> range (0,-10,-1) [0,-1,-2,-3, -4, -5,-6,-7,-8, -9]>>> range (0) []>>> range (1, 0) []
-
-
—————————————————————————————————————————————
-
-
-
- Range (
stop )
-
- Range (
start,
stop[,
step] )