Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I've been trying to find out how to represent a maximum integer, and I've read to use "sys.maxint". However, in Python 3 when I call it I get:

AttributeError: module 'object' has no attribute 'maxing'

2 Answers

0 votes
by (106k points)
edited by

In Python 3, sys.maxint does following:-

import sys 

INT_MAX = sys.maxsize 

INT_MIN = -sys.maxsize-1 

print(INT_MAX,INT_MIN)

To know more about this you can have a look at the following video tutorial:-

0 votes
by (20.3k points)

If you want to determine the maximum size of int in C when compiled the same way as Python was, you can try using the struct module to find out like this:

>>> import struct

>>> platform_c_maxint = 2 ** (struct.Struct('i').size * 8 - 1) - 1

Note: Python 3 ints do not have a maximum.

But, If you are curious about the internal implementation details of Python 3 int objects, then look at sys.int_info for bits per digit and digit size details.

Related questions

0 votes
1 answer
asked Jul 13, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Sep 26, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
5 answers
0 votes
1 answer
asked Mar 17, 2021 in Python by laddulakshana (16.4k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...