Python整数范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4581842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python integer ranges
提问by nos
In Python, is there a way to get the largest integer one can use? Is there some pre-defined constant like INT_MAX?
在 Python 中,有没有办法获得可以使用的最大整数?是否有一些像 INT_MAX 这样的预定义常量?
采纳答案by Matthew Flaschen
Python has arbitrary precision integers so there is no true fixed maximum. You're only limited by available memory.
Python 具有任意精度整数,因此没有真正的固定最大值。您仅受可用内存的限制。
In Python 2, there are two types, intand long. ints use a C type, while longs are arbitrary precision. You can use sys.maxintto find the maximum int. But ints are automatically promoted to long, so you usually don't need to worry about it:
在 Python 2 中,有两种类型,int和long. ints 使用 C 类型,而longs 是任意精度。您可以使用sys.maxint来查找最大值int。但是ints 会自动提升为long,因此您通常无需担心:
sys.maxint + 1
works fine and returns a long.
工作正常并返回一个long.
sys.maxintdoes not even exist in Python 3, since intand longwere unified into a single arbitrary precision inttype.
sys.maxint在 Python 3 中甚至不存在,因为int和long被统一为一个任意精度int类型。

