Python: Range() maximum size; dynamic or static?(Python: Range() 最大尺寸;动态的还是静态的?)
问题描述
我对 python 还是很陌生,所以我照常通过 Project Euler 来解决我脑海中的逻辑问题.
I'm quite new to python, so I'm doing my usual of going through Project Euler to work out the logical kinks in my head.
基本上,我需要尽可能大的列表大小,即 range(1,n),而不会溢出.
Basically, I need the largest list size possible, ie range(1,n), without overflowing.
有什么想法吗?
推荐答案
看看内置模块源码
总结:如果列表中的元素多于有符号长整数,您将收到溢出错误.在 32 位 Python 上是 2**31 - 1
,在 64 位 Python 上是 2**63 - 1
.当然,即使是低于该值的值,您也会收到 MemoryError.
Summary: You'll get an OverflowError if the list has more elements than can be fit into a signed long. On 32bit Python that's 2**31 - 1
, and on 64 bit Python that's 2**63 - 1
. Of course, you will get a MemoryError even for values just under that.
这篇关于Python: Range() 最大尺寸;动态的还是静态的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python: Range() 最大尺寸;动态的还是静态的?


基础教程推荐
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01