What is the integer limit in python?

In Python3, int has no max limit.

Python2 has two integer types, int and long, but Python3 has only int. int in Python3 is equivalent to long in Python2, and there is no max limit. You can handle as large value as memory is available.

This article describes the following contents.

  • int and long in Python2
  • int in Python3 has no max limit

See the following article for the maximum and minimum values of the floating-point number float.

  • Maximum and minimum float values in Python

Note that NumPy uses data types with a fixed number of bits, such as int32 (32-bit integer) and int64 (64-bit integer).

  • NumPy: Cast ndarray to a specific dtype with astype()

int and long in Python2

Python2 has two integer types, int and long.

  • 5.4 Numeric Types — int, float, long, complex — Python 2.7.18 documentation

You can get the max value of int with sys.maxint. The min value (the largest negative value) is -sys.maxint-1.

  • 28.1. sys.maxint — System-specific parameters and functions — Python 2.7.18 documentation

sys.maxint is at least 2**31-1, and on a 64-bit environment, it is 2**63-1.

long has no maximum and minimum limit.

int in Python3 has no max limit

int in Python3 corresponds to long in Python2, and there is no max and min limit.

The sys.maxint constant was removed, since there is no longer a limit to the value of integers. However, sys.maxsize can be used as an integer larger than any practical list or string index. It conforms to the implementation’s “natural” integer size and is typically the same as sys.maxint in previous releases on the same platform (assuming the same build options). What’s New In Python 3.0 — Python 3.8.4 documentation

In Python3, sys.maxint has been removed, and sys.maxsize has been added.

  • sys.maxsize — System-specific parameters and functions — Python 3.8.4 documentation

sys.maxsize is 2**31-1 on a 32-bit environment and 2**63-1 on a 64-bit environment, like sys.maxint in Python2.

import sys

print(sys.maxsize)
# 9223372036854775807

print(type(sys.maxsize))
# <class 'int'>

print(sys.maxsize == 2**63 - 1)
# True

Converted to binary and hexadecimal numbers with bin() and hex(), sys.maxsize is expressed as follows.

  • Convert binary, octal, decimal, and hexadecimal in Python

print(bin(sys.maxsize))
# 0b111111111111111111111111111111111111111111111111111111111111111

print(hex(sys.maxsize))
# 0x7fffffffffffffff

sys.maxsize is not the max value of int, and you can handle larger values as memory is available.

i = 10**100

print(i)
# 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

print(i > sys.maxsize)
# True

The floating-point number float has inf representing infinity. inf is judged to be larger than any value of int.

print(float('inf'))
# inf

print(i > float('inf'))
# False

See the following article about infinity inf.

  • "inf" for infinity in Python

What is an integer limit?

The number 2,147,483,647 (or hexadecimal 7FFFFFFF16) is the maximum positive value for a 32-bit signed binary integer in computing. It is therefore the maximum value for variables declared as integers (e.g., as int ) in many programming languages.

How large can an integer in python be in 64

int in Python3 has no max limit maxsize has been added. sys. maxsize is 2**31-1 on a 32-bit environment and 2**63-1 on a 64-bit environment, like sys. maxint in Python2.

How large can an integer be in Python 3?

Integers in Python 3 are of unlimited size. Python 2 has two integer types - int and long.