The Python range()
function is just a shortcut for generating a list, so you can use ranges in all the same places you can use lists.
rang()函数用于方便地产生一个表,用例:
range(6) # => [0,1,2,3,4,5]
range(1,6) # => [1,2,3,4,5]
range(1,6,3) # => [1,4]
三种使用方法:
- range(stop)
- range(start, stop)
- range(start, stop, step)
range()
function returns a list of numbers from
start up to (but not including)
stop. Each item increases by
step.
如果缺省start 和step 则默认start=0,step=1
例(1):
def my_function(x):
f