- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the maximum possible value of an integer in Python?
Unlike C/C++ Long in Python 3 have unlimited precision and there is no explicitly defined limit. The amount of available address space considered to be the practical limit.
In python 2, integers will automatically switch to longs when they grown beyond their limit −
Python 2
>>> import sys >>> type(sys.maxint) <type 'int'> >>> type(sys.maxint + 1) <type 'long'>
Python 3
Maxint was removed in python 3, but sys.maxsize can often be used instead.
>>> import sys >>> type (sys.maxsize) <class 'int'> >>> type (sys.maxsize + 1) <class 'int'>
From above output we can see, in python 3 int and long are actually merged and the value has no such importance.
#Python 2.7
>>> import sys >>> print sys.maxint# Max Integer value 2147483647 >>> print -sys.maxint -1# Min. Ineteger value -2147483648
But in python 3 we can assign a higher value than this as the range will be increased this time. The sys.maxint is replace by sys.maxsize.
#In Python 3.6
>>> import sys >>> print(sys.maxsize) 2147483647
Largest & Smallest integers, longs and float values
#Python 2.7 import sys print("Float value information: ",sys.float_info) print("\n") print("Long Integer value information: ",sys.long_info) print("\n") print("Maximum size of an integer: ",sys.maxsize)
output
('Float value information: ', sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)) ('Long Integer value information: ', sys.long_info(bits_per_digit=30, sizeof_digit=4)) ('Maximum size of an integer: ', 9223372036854775807L)
#Python 3.6
import sys print("Float value information: ",sys.float_info) print("\nInteger value information: ",sys.int_info) print("\nMaximum size of an integer: ",sys.maxsize)
output
Float value information: sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1) Integer value information: sys.int_info(bits_per_digit=15, sizeof_digit=2) Maximum size of an integer: 2147483647
- Related Articles
- What is the maximum possible value of an integer in C# ?
- What is the maximum possible value of an integer in Java ?
- What is the maximum value of float in Python?
- Program to find maximum possible value of an expression using given set of numbers in Python
- Program to find maximum possible value of smallest group in Python
- What is possible key/value delimiter in Python dictionary?
- Find the maximum possible value of the minimum value of modified array in C++
- if x + y = 50, what is the maximum value of the product of x and y that is possible?
- Program to find minimum possible maximum value after k operations in python
- C++ program to find maximum possible value for which XORed sum is maximum
- How to convert an integer to an ASCII value in Python?
- Program to find lowest possible integer that is missing in the array in Python
- Maximum value of an integer for which factorial can be calculated on a machine in C++
- Find maximum possible stolen value from houses in C++
- C++ program to find maximum possible value of XORed sum

Advertisements