Xrange ()
The xrange () function usage is exactly the same as range , and the difference is that instead of an array, a generator is generated.
Grammar:
Xrange (stop) xrange (start, stop[, step])
- Start: Count starts from start. The default is starting from 0. For example, range (5) is equivalent to range (0, 5);
- End: Count to end, but do not include end. For example: Range (0, 5) is [0, 1, 2, 3, 4] No 5
- Step: Step, Default is 1. Example: Range (0, 5) is equivalent to range (0, 5, 1)
Example
1>>>xrange (8)2Xrange (8)3>>> List (xrange (8))4[0, 1, 2, 3, 4, 5, 6, 7]5>>> Range (8)#Range uses6[0, 1, 2, 3, 4, 5, 6, 7]7>>> xrange (3, 5)8Xrange (3, 5)9>>> List (xrange (3,5))Ten[3, 4] One>>> Range (3,5)#Use range A[3, 4] ->>> xrange (0,6,2) -Xrange (0, 6, 2)#Step size is 2 the>>> list (xrange (0,6,2)) -[0, 2, 4] ->>>
Output:
1 True 2 True 3 True 4 False
Python function-xrange ()