有人知道 Python 如何在内部管理 int 和 long 类型吗?
- 它会动态选择正确的类型吗?
- int 的限制是多少?
- 我正在使用 Python 2.6,与以前的版本有什么不同吗?
我应该如何理解下面的代码?
>>> print type(65535)
<type 'int'>
>>> print type(65536*65536)
<type 'long'>
更新:
>>> print type(0x7fffffff)
<type 'int'>
>>> print type(0x80000000)
<type 'long'>
原文由 luc 发布,翻译遵循 CC BY-SA 4.0 许可协议
int
和long
“统一” 了几个版本。在此之前,可以通过数学操作溢出 int。3.x 通过完全消除 long 并只有 int 进一步推进了这一点。
sys.maxint
包含 Python int 可以容纳的最大值。sys.getsizeof()
。sys.maxsize
包含 Python int 可以达到的最大字节数。sys.maxsize
的值。