The advantage of the range type over a regular list or tuple is that a range object will always take the same (small) amount of memory, no matter the size of the range it represents (as it only stores the start, stop and step values, calculating individual items and subranges as needed).
这取决于您的python版本。如果您使用的是python2,它将为range函数创建列表。分别,list需要O(n)内存复杂度。否则,如果使用的是python3,它将创建生成器。在
更新:正如Vineeth所说的range不是迭代器。很抱歉误导你。在
根据文件:
相关问题 更多 >
编程相关推荐