30

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 !

Trent
  • 1,275
  • 7
  • 17
  • 22
  • You couldn't find the IEEE floating-point information? http://docs.python.org/tutorial/floatingpoint.html It seems pretty clear. – S.Lott Mar 29 '11 at 09:58
  • Python uses 64 bit floats (Double precision IEEE754) and unlimited (well, as much as your computer can handle) integer lengths. – Eric Jin Jun 09 '19 at 13:38

4 Answers4

66

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.

S.Lott
  • 384,516
  • 81
  • 508
  • 779
CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
  • 14
    A tl;dr version: Small Python integer numbers fit into machine word of the platform (e.g. 32 bit). If a number doesn't fit, it is automatically promoted to a 'long' integer which is as long as your RAM allows. You can't really have an integer overflow. If you want to pack precise number of bits (e.g. to interface to C code), you `import struct, ctypes`. – 9000 Mar 29 '11 at 10:08
  • While it's fascinating to know that it's only limited by the memory, it'd also be nice to know how Python implements the storage and arithmetic operations of large numbers, internally. I remember a blog that mentioned that numbers are stored with a base of `2^30`, but that'd mean there is a limit. In your answer, could you also link to any explanation that provides some insight on the internal implementation? This would be an amazing piece of information for any Pythonista! – Nav Apr 04 '21 at 13:46
10

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.

Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
Hari Palappetty
  • 539
  • 6
  • 14
7

See the sys module:

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

and so on.

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
-1

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

eat
  • 7,440
  • 1
  • 19
  • 27