Home > Article > Backend Development > What does python range mean?
Detailed usage of python range() function
Function prototype: range(start, end, scan):
Parameter meaning: start: counting starts from start. The default is to start from 0. For example, range (5) is equivalent to range (0, 5);
end: counting to the end of end, but not including end. For example: range (0, 5) is [0, 1, 2, 3 , 4] No 5
scan: The distance between each jump, the default is 1. For example: range(0, 5) is equivalent to range(0, 5, 1)
##Basic usage example:Python >>> for i in range(1,5): print(i) 1 2 3 4 >>> for i in range(5): print(i) 0 1 2 3 4 >>> for i in range(0,5,2): print(i) 0 2 4 >>> for i in range(0,-5,-2): print(i) 0 -2 -4Related recommendations:《
Python video tutorial》
Note:The difference between python2 and python3:
python3 returns an iteration value:Python3
print(range(1,5)) range(1, 5) # 正确打印方法 list(range(1,5)) [1, 2, 3, 4]python2 returns a list:
Python2
>>> range(1,5) [1, 2, 3, 4]
The above is the detailed content of What does python range mean?. For more information, please follow other related articles on the PHP Chinese website!