Describe
The range () function creates a set of continuously increasing integers that work like slices and are typically used in a for loop.
Grammar
Range (start, stop[, step])
Parameter description:
- 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)
return value
A list of integers is returned in Python2, and an iteration value is returned in Python2.
Instance
Python2:
>>>range # from 0 onwards to 10[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> range (1, one) # from 1 to 11[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]>>> range (0,, 5) # Steps of 5[0, 5, ten,, 25]>>> range (0,, 3) # step is 3[ 0, 3, 6, 9]>>> range (0,-10, 1) # negative number [0,-1,-2, -3, -4, -5,-6,-7,-8, -9]>>> range (0) []>>> R Ange (1, 0) []
Python3:
>>> Range (0, ten) >>> range (0) range (0, 0)
The following is the use of range in for, looping out each letter of Runoob:
>>>x = ' Runoob ' >>> for I in range (len (x)): ... . Print (X[i]) ... runoob>>>
Python Range () function