What is the Max and Minimum Value of int type in Python?


Python Max and Min Int value example

If you come from a programming background of Java or C#, you would have known that there is a limit to the max and the min size of an integer datatype based on the underlying system architecture (which is -231 to -231-1 for 64 bit Operating Systems)

But, do you know that the int data type is an arbitrary precision integer, which means that it can represent integers of any size without overflow.

Reference:
https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex

"An integer giving the maximum value a variable of type Py_ssize_t can take. It’s usually 2**31 - 1 on a 32-bit platform and 2**63 - 1 on a 64-bit platform."

Reference:
https://docs.python.org/3/library/sys.html#sys.maxsize

Example:
import sys

print(f"Max Int: {sys.maxsize}") 
print(f"Min Int: {-sys.maxsize - 1}")
Output:
Max Int: 9223372036854775807
Min Int: -9223372036854775808

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright Β© Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap