Python 数量限制
我知道在大多数(如果不是所有)编程语言中,整数、浮点数等都有可以容纳的最大数量,无论是无符号的还是有符号的。例如pascal的int类型最多只能容纳32768~。
我想知道的是,python 的 int 和浮点变量的限制是什么。我尝试了一个小程序来产生非常大的数字,但没有遇到任何错误。这些变量的大小是否有限制?
我查看了文档,但找不到我要找的内容:/
将不胜感激,谢谢!
I know in most, if not all programming languages, integers, floats etc all have a maximum amount they can hold, either unsigned or signed. Eg pascal's int type can only hold up to 32768 ~.
What i wanted to know was, what is the limit on python's int and floating point variables. I tried a little program to produce extremely large numbers, but i ran into no errors. Does it even have limits on how big these variables can be ?
I looked in the documentation and couldn't find what i was looking for :/
Help would be greatly appreciated, thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
早期版本对
int
有限制,但现在它被删除了,所以你可以说没有限制,这取决于你的计算机的内存。查看这篇文章。Earlier Versions had a limit on
int
but its removed now, so you can say there is no limit, it depends on the memory of your computer. Check this article.早期版本的 Python 曾经对
int
有限制。但是,由于 Python 将整数视为对象,因此该值被删除。因此,尽管 Python 为对象引用所指向的值分配 32 位,但当该值超过 2^32 时,它会一直向上移动到计算机上 RAM 的大小。There used to be a limit in earlier versions of Python for
int
. But, this is dropped as Python treats integers as objects. So, although Python allocates 32 bits for the value object reference is pointing to, as the value goes beyond 2^32 it can keep moving up all the way up to the size of RAM on your computer.请参阅 sys 模块:
等等。
See the sys module:
and so on.
这个文档提供了很好的起点,例如
sys.float_info
。This document gives good starting point, like
sys.float_info
.