This example describes the Xrange usage in Python. Share to everyone for your reference. Specifically as follows:
Let's look at the following examples:
>>> X=xrange (0,8)
>>> print x
xrange (8)
>>> print x[0]
0
>> > Print x[7]
7
>>> print x[8]
traceback (most recent call last):
File ' <stdin> ', line 1 , in <module>
Indexerror:xrange Object index out of range
>>> x=range (0,8)
>>> Print x
[0, 1, 2, 3, 4, 5, 6, 7]
>>> print x[0]
0
>>> print x[8]
traceback (MOS T recent call last):
File "<stdin>", line 1, in <module>
Indexerror:list index out of range
RA Nge ([Start,] stop [, step])->list of integers
Range () returns a list of numbers that are incremented or decremented, with the element value of the list determined by three parameters
Start represents the value at which the list starts, and defaults to "0".
Stop indicates the value of the end of the list, which is an indispensable parameter
The parameter step represents the stride size, and the default value is 1.
Range () returns a list of numbers that are incremented or decremented.
Xrange is a class that returns a Xrange object. traversal using xrange (), which returns only one value per traversal. Range () returns a list that evaluates and returns all values at once. Therefore, the execution efficiency of xrange () is higher than range ()
I hope this article will help you with your Python programming.