range()语法格式为
range([start,] stop [,step])
# 有三种用法
range(stop)
range(start,stop)
range(start,stop,step)
该函数返回具有惰性求值特点的range对象,其中包含左闭右开区间,参数start默认为0,step默认为1
>>> range(5)
range(0, 5)
>>> list(_)
[0, 1, 2, 3, 4]
>>> list(range(1,10,2))
[1, 3, 5, 7, 9]
>>> list(range(9,0,-2))
[9, 7, 5, 3, 1]
>>> for i in range(4):
... print(3,end=‘ ‘)
...
3 3 3 3 >>>
>>> for i in range(200,0,-1):
... if i%17==0:
... print(i)
... break
...
187
原文:https://www.cnblogs.com/zxbdboke/p/10468408.html