Python如何管理int和long? [英] How does Python manage int and long?
本文介绍了Python如何管理int和long?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道Python如何管理内部int和long类型?
Does anybody know how Python manage internally int and long types?
- 它是否动态选择正确的类型?
- int的限制是什么?
- 我使用的是Python 2.6,与以前的版本有什么不同?
我应该如何理解下面的代码?
How should I understand the code below?
>>> print type(65535)
<type 'int'>
>>> print type(65536*65536)
<type 'long'>
更新:
>>> print type(0x7fffffff)
<type 'int'>
>>> print type(0x80000000)
<type 'long'>
推荐答案
int
和 long
是统一退回几个版本。在此之前,有可能通过数学操作溢出一个int。
int
and long
were "unified" a few versions back. Before that it was possible to overflow an int through math ops.
3.x通过完全消除int并且只有很长时间来进一步提高它。
3.x has further advanced this by eliminating int altogether and only having long.
Python 2: sys.maxint
包含Python int可以容纳的最大值。
Python 2: sys.maxint
contains the maximum value a Python int can hold.
Python 3: sys.maxsize
包含Python int可以容纳的最大值。
Python 3: sys.maxsize
contains the maximum value a Python int can hold.
这篇关于Python如何管理int和long?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文