开发者

Python Number Limit [duplicate]

开发者 https://www.devze.com 2023-02-20 06:35 出处:网络
This question already has answers here: Maximum and Minimum values for ints (10 answers) What is the maximum float in Python?
This question already has answers here: Maximum and Minimum values for ints (10 answers) What is the maximum float in Python? (4 answers) Closed 21 days ago.

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, 开发者_如何学Pythonbut 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 !


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.


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.


See the sys module:

import sys
dir(sys)
print sys.maxint
help(sys.float_info)

and so on.


This document gives good starting point, like sys.float_info.

0

精彩评论

暂无评论...
验证码 换一张
取 消