Cheap VPS host selection
Provide server host evaluation information

What is the function of range () in python

In Python, range() The function is used to create an integer sequence. It is often used to control the number of iterations in a loop. range() A function can accept one, two, or three parameters, representing the start value, the end value, and the step size, respectively.

When only one parameter is passed, range(stop) Will generate from 0 to stop-1 The default step is 1.

When two parameters are passed, range(start, stop) Will generate from start Start to stop-1 The default step is 1.

When three parameters are passed, range(start, stop, step) Will generate from start Start to stop-1 Integer sequence of, step size is step

through the use of range() Function, we can easily generate an integer sequence within the required range and iterate in the loop. For example:

 for i in  range ( one , ten , two ): print (i) #Output: 1 3 5 7 9

Use of the above codes range(1, 10, 2) An odd number sequence from 1 to 9 is generated, and each number is printed in the loop.

Do not reprint without permission: Cheap VPS evaluation » What is the function of range () in python