|
发表于 2020-11-5 21:48:23
|
显示全部楼层
=========帮助文档===========
>>> help(range)
Help on class range in module builtins:
class range(object)
| range(stop) -> range object
| range(start, stop[, step]) -> range object
|
| Return an object that produces a sequence of integers from start (inclusive)
| to stop (exclusive) by step. range(i, j) produces i, i+1, i+2, ..., j-1.
| start defaults to 0, and stop is omitted! range(4) produces 0, 1, 2, 3.
| These are exactly the valid indices for a list of 4 elements.
| When step is given, it specifies the increment (or decrement).
==============详解==========
range(start,stop,step)
start可省略,默认是0
stop不可省略,表示终止值
step可省略,默认是1
range(-10),可以理解为range(0,-10,1)
上面已经给出了答案,正确的做法是range(0,-10,-1) |
|