To find the maximum and minimum values for an integer we use maxsize method from the sys module. The sys.maxsize gives us the maximum value whereas the negative version of this value i.e. -sys.maxsize-1 gives us the minimum value for the integer. Also, we can get the max and min values of integers using numpy module in Python
In this post, we will cover the details of how we get the maximum and minimum values for the integers using the two methods that are:
- Method 1: Using maxsize method from the sys module.
- Method 2: Using the Numpy module in Python.
How to Find Maximum/Minimum Values for Integers in Python?
There are two major ways to find the minimum and maximum values for integers in Python. let’s discuss them one by one.
Method 1: Using maxsize method from the sys module
To find the maximum and minimum values for integers in Python we can use the maxsize method from the sys module. The sys.maxsize gives us the maximum value whereas the negative version of this value i.e. -sys.maxsize-1 gives us the minimum value for the integer.
Syntax
The code can simply be written as follows:
import sys
# max integer value
int_max = sys.maxsize
# min integer value
int_min = -sys.maxsize - 1
print("maximum integer value: ", int_max)
print("The minimum integer value: ", int_min)
In the above code:
- We wrote the statement, “sys.maxsize” to find the maximum value of an integer.
- For minimum value, we wrote negation of the above statement i.e. “-sys.maxsize-1” or we can also write it as “~sys.maxsize”.
The output for the above query is:

Method 2: Using the Numpy module in Python
We can also find the maximum and minimum value of an integer in Python by using the Numpy module of Python. The numpy.iinfo() is the method available in Numpy to get the system size bits. This method returns the max and min values of the integers of different sizes.
Syntax
We can write its simple syntax as follows:
numpy.iinfo(numpy.int(Size_of_integer))
The size of the integer is passed into the function.
Let’s see how it works.
import numpy
# Finding the max and min val for int-8 size
print(numpy.iinfo(numpy.int8))
# Finding the max and min val for int-16 size
print(numpy.iinfo(numpy.int16))
# Finding the max and min val for int-32 size
print(numpy.iinfo(numpy.int32))
# Finding the max and min val for int-64 size
print(numpy.iinfo(numpy.int64))
The output of the above program will give the max and min values of the integers. The output looks like this:

This was all about finding the max and min values for integers.
Conclusion
In Python, a couple of methods are used to find the maximum and minimum values for integers. The first and the most common one is by using the maxsize method and the second one is by using the numpy.iinfo() method offered by Numpy. In this post, we have discussed both the methods along with the syntax as examples practically.
Frequently Asked Questions
How can I find the maximum value of an integer in Python using sys module?
You can find the maximum value of an integer in Python using sys module by utilizing the sys.maxsize method.
What is the negative value of sys.maxsize-1 used for in Python?
In Python, the negative value of sys.maxsize-1 is used to represent the minimum value for an integer.
How do I find the minimum integer value in Python using sys module?
To find the minimum integer value in Python, you can use the negative value of sys.maxsize-1 or -sys.maxsize-1.
Can I use the Numpy module in Python to find the maximum and minimum values of integers?
Yes, you can use the Numpy module in Python to find the maximum and minimum values of integers using numpy.iinfo() method.
What are the two methods to find maximum and minimum values of integers in Python?
The two methods to find maximum and minimum values of integers in Python are using sys module's maxsize method and Numpy module's numpy.iinfo() method.
How to write Python code to display the maximum and minimum integer values?
You can write Python code to display the maximum and minimum integer values by importing sys module, then using sys.maxsize and -sys.maxsize-1 to get the values.
What does the sys.maxsize represent in Python?
In Python, sys.maxsize represents the maximum value that an integer can hold on a given platform.
Is there an alternative way to find the minimum integer value in Python without using sys.maxsize?
Yes, you can find the minimum integer value in Python without using sys.maxsize by directly assigning the value -9223372036854775808 to a variable.