python的range到底是如何运作?

它不是返回一个根据两个或者三个参数确定的数组么? 为什么要得到数组还要加上list

阅读 2.5k
3 个回答

range是一个类 # <class 'range'>
range(10)是一个对象
list 是一个类 # <class 'list'>
list(range(10)) 是把range对象转为list对象啊,也就是常用的列表
源码不好理解的话,可以看看官方文档https://docs.python.org/3/lib...

新手上路,请多包涵

Python range (start, end) never include end it has a very simple answer because index always starts with ZERO in python. if you count total numbers between range (5) you will get [0,1,2,3,4] i.e. total count is 5.
return result determined by value constraints. it will return empty if value constraint doesn't meet some of the value constraints are step value cannot be zero or greater than stop

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题