python range()function
>>>range(-1,-5)[]>>>range(-1,-len('word')-1,-1)[-1,-2,-3,-4]>>>range(-10,-100)[]>>>ra...
>>> range(-1,-5)[]
>>>range(-1,-len('word')-1, -1)
[-1, -2, -3, -4]
>>> range(-10,-100)
[]
>>> range(-10, -100, -30)
[-10, -40, -70]
请解释一下每个函数都是什么意思为什么range(1,5)能输出[1,2,3,4]而range(-1,-5)不输出[-1,-2,-3,-4]谢啦~ 展开
>>>range(-1,-len('word')-1, -1)
[-1, -2, -3, -4]
>>> range(-10,-100)
[]
>>> range(-10, -100, -30)
[-10, -40, -70]
请解释一下每个函数都是什么意思为什么range(1,5)能输出[1,2,3,4]而range(-1,-5)不输出[-1,-2,-3,-4]谢啦~ 展开
2个回答
展开全部
因为range函数的step参数默认为1,所以range(-1, -5)返回一个空列表。
>>> range(-1, -5, -1)
[-1, -2, -3, -4]
>>> help(range)
Help on built-in function range in module __builtin__:
range(...)
range(stop) -> list of integers
range(start, stop[, step]) -> list of integers
Return a list containing an arithmetic progression of integers.
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
When step is given, it specifies the increment (or decrement).
For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!
These are exactly the valid indices for a list of 4 elements.
>>> range(-1, -5, -1)
[-1, -2, -3, -4]
>>> help(range)
Help on built-in function range in module __builtin__:
range(...)
range(stop) -> list of integers
range(start, stop[, step]) -> list of integers
Return a list containing an arithmetic progression of integers.
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
When step is given, it specifies the increment (or decrement).
For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!
These are exactly the valid indices for a list of 4 elements.
推荐于2017-12-23
引用柒涩琴的回答:
因为range函数的step参数默认为1,所以range(-1, -5)返回一个空列表。
>>> range(-1, -5, -1)
[-1, -2, -3, -4]
>>> help(range)
Help on built-in function range in module __builtin__:
range(...)
range(stop) -> list of integers
range(start, stop[, step]) -> list of integers
Return a list containing an arithmetic progression of integers.
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
When step is given, it specifies the increment (or decrement).
For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!
These are exactly the valid indices for a list of 4 elements.
因为range函数的step参数默认为1,所以range(-1, -5)返回一个空列表。
>>> range(-1, -5, -1)
[-1, -2, -3, -4]
>>> help(range)
Help on built-in function range in module __builtin__:
range(...)
range(stop) -> list of integers
range(start, stop[, step]) -> list of integers
Return a list containing an arithmetic progression of integers.
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
When step is given, it specifies the increment (or decrement).
For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!
These are exactly the valid indices for a list of 4 elements.
展开全部
# range(start,stop,step) 可以接受三个参数 # 只给一个参数 s,表示 从0到srange(5)# [0,1,2,3,4] # 两个参数,s,e,表示从s到erange(5,10)# 5,6,7,8,9 # 三个参数 s,e,i 表示从s到e,间隔i取数range(0,10,2)# [0,2,4,6,8]
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |