range

来源:互联网 发布:python中字符串的函数 编辑:程序博客网 时间:2024/06/05 14:12
range([start,] stop [, step])

start

The value of the start parameter (or0 if the parameter was not supplied)

stop

The value of the stop parameter

step

The value of the step parameter (or1 if the parameter was not supplied)



>>> list(range(5))
[0, 1, 2, 3, 4]
>>> list(range(1,5))
[1, 2, 3, 4]
>>> list(range(1,10,2))
[1, 3, 5, 7, 9]
>>> list(range(1,10,3))
[1, 4, 7]
>>> list(range(5,0,-1))
[5, 4, 3, 2, 1]