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() 最大尺寸;动态的还是静态的?
基础教程推荐
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
