Home >Backend Development >Python Tutorial >How to use the range() function in python
How to use the range() function in python
The range() function in python can create a list of integers, Generally used in for loops.
range() function syntax:
range(start,stop[,step])
Recommendation:Python tutorial
Parameter description:
star: Counting starts from star. The default is to start from 0.
stop: Counting ends at stop, but does not include stop.
step: Step Long, the default is 1.
Example:
>>>range(10) # 从 0 开始到 10,没有10 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(1, 11) # 从 1 开始到 11,没有11 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> range(0, 30, 5) # 步长为 5 [0, 5, 10, 15, 20, 25] >>> range(0, 10, 3) # 步长为 3 [0, 3, 6, 9] >>> range(0, -10, -1) # 负数 [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] >>> range(0) [] >>> range(1, 0) []
Many python video tutorials, all on the PHP Chinese website, welcome to learn online!
The above is the detailed content of How to use the range() function in python. For more information, please follow other related articles on the PHP Chinese website!