Python Range Function Usage
One, in the Python development application, the range function is very important, but also more commonly used :
first look at the prototype of the range function: range (start, end, scan)
parameter resolution:
Start: Count starts from start. The default is starting from 0. For example, range (5) is equivalent to range (0, 5);
End: The technology ends with end, but does not include end. For example: Range (0, 5) is [0, 1, 2, 3, 4] No 5 (commonly known: after the package is not wrapped)
Scan: The distance between each hop is 1 by default. Example: Range (0, 5) is equivalent to range (0, 5, 1)
Second, according to the specific code, see a range of functions in the specific use of Python3.7:
Since the range (0,5) in Python 3.7 does not directly output the sequence [0, 1, 2, 3, 4], this is where Pycharm uses the For loop to show the app
1 forIinchRange (5):2 Print(i,end=' ')#Output [0, 1, 2, 3, 4]3 4 forIinchRange (0,5):5 Print(i,end=' ')#Output [0, 1, 2, 3, 4]6 7 forIinchRange (-5):8 Print(i,end=' ')#Output []9 Ten forIinchRange (0, 5, 2): One Print(I, end=' ')#Output [0, 2, 4] A - forIinchRange (0,-5, 2): - Print(I, end=' ')#Output [0, -2, -4]
Range function Case
This also makes a bubble sort based on the range function.
1Array = [1, 2, 5, 3, 6, 8, 4]2 forIinchRange (len (array)-1, 0, 1):3 Print(Array[i], end=' ')4 5 forIinchRange (0, Len (array), 1):6 Print(i)7 forJinchRange (i + 1, len (array), 1):8 ifARRAY[J] <Array[i]:9ARRAY[J], array[i] =Array[i], Array[j]Ten One Print(array)
python bubble sort
Parsing Python range function usage