Maximum Integer and Maximum Floating Point Instances in Python3

  • 2021-07-13 05:34:20
  • OfStack

Maximum integer in Python

In Python, the maximum value of int can be obtained by sys module. The method used in python2 is


import sys
max = sys.maxint
print (max)

The method used in python3 is:


import sys
max = sys.maxsize
print (max)

Get the maximum floating point number in Python

Method 1: Use the sys module


>>> import sys
>>> sys.float_info
sys.floatinfo(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2
250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsil
on=2.2204460492503131e-16, radix=2, rounds=1)
>>> sys.float_info.max
1.7976931348623157e+308

Method 2: Use the float function


>>> infinity = float("inf")
>>> infinity
inf
>>> infinity / 10000
inf

Related articles: