作用
产生一系列整数,返回一个range对象
语法:
range(start,end,step)
range(start,end)
range(end)
range函数中带有三个参数:start、end、step。
例如:产生数字0-1的列表:>>> list(range(0,10,1))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> list(range(0,10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
三种情况输出结果相同
start 起始值(包含),end 终止值(不包含),step 步长。
range(start,end)——省却step时,默认步长为1;range(end)——省却step、start时,默认步长为1,起始值为0
注意:step的值不能为0或者浮点数>>> list(range(2,10,2))
[2, 4, 6, 8]>>> list(range(2,10,2.5))
Traceback (most recent call last):
File "", line 1, in
list(range(2,10,2.5))
TypeError: 'float' object cannot be interpreted as an integer
最后
以上就是大力柜子最近收集整理的关于range函数python三个参数_python3.5如何使用range函数的全部内容,更多相关range函数python三个参数_python3内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复