Menu Close

How to get the maximum and minimum values for ints with Python?

Sometimes, we want to get the maximum and minimum values for ints with Python.

In this article, we’ll look at how to get the maximum and minimum values for ints with Python.

How to get the maximum and minimum values for ints with Python?

To get the maximum and minimum values for ints with Python, we can use the sys.maxsize property.

For instance, we write

import sys

max_size = sys.maxsize
min_size = -sys.maxsize - 1

to get the max value with sys.maxsize.

And we get the min value with -sys.maxsize - 1.

Conclusion

To get the maximum and minimum values for ints with Python, we can use the sys.maxsize property.

Posted in Python, Python Answers