How to find the maximum and minimum value accepted by the integer?

So then what will happen if we provide the value to the int variable out of its range?

As we know we don’t specify the data type of value while using a numeric variable in python. When you assign the value out of int size limit, the variable is converted to long int.

2. long

There is no precision limit to the long integer.

Yes, it’s right!

So you can enter any number without limit. When you assign value to the value greater than int max limit (i.e. 2147483647), it is treated at long int.

for example,

#World Total Population
population =7514815137
type(population)
#<type,'long'>

In fact, this limit depends on the size of memory (RAM). The size of the value in a variable cannot be greater than the size of actual memory space you are using for running python program.

But how can you test it out the limit range of long int?

To test this, I can’t suggest you to keep typing the integers. It may hurt your finger typing 😛

The smart way is to generate this number as an output of the program.

One of the clever examples is to find the factorial of 6000.

There are so many Python interviews; the interviewer asks to find out the factorial of a big number.

If you are coming from other programming languages, you might consider it as a big challenge. In many of the programming languages, finding the factorial of big number crashes your program if the factorial of the number goes out of the integer range limit.

But this is not the case for Python. You can find the factorial of any number as long as your memory is not exhausted. It is near to impossible to exhaust the memory limit unless you are using 128KB RAM 😀

3. float

Implementation of float in Python is similar to the double in C and C++.

Unlike to the long data type, float has max and min value limit.

How to get Max and Min possible value of the float?

You can use sys.float_info to get max and min possible value for float numeric type in Python.

You will not find the use of this variable in general arithmetic operation. It is mostly used in programming for data science and for other scientific purposes.

5. boolean

Above four are the main data type of the numeric variable. There is also one numeric type called boolean.

It accepts the value 0 and 1. If you pass the value 0 or 1, the system can not identify if the variable is an integer or boolean type. It is simply treated as an int, so I will not consider it as the main data type.

int var = 1
type(var)
#<type, 'int'>

It is nothing but the subtype of an integer.

Now let’s see, some of the frequently asked questions on Numeric Data types…

How does system identify the Python Numeric Data Types of the Variable?

It identifies based on the value and range of the value, you are providing to the variable.

Using value passing to the variable

If you are providing integer value without decimal point it is considered as an int value. All the numerical values with a decimal point is a float in Python.

Using a range of the value assigned to a variable

Integer and float value has a limit for the range of values assigned to it.

When the range of integer value goes beyond the limit the variable is converted into a long data type. This we will see in detail in long data type.

How to know the Datatype of a Numeric Variable?

You can simply get the type of a variable by using inbuilt type function as below.

In your program, you may want to know the data type of the variable. And based on the type of variable, you may want to manipulate and perform the operation. You can refer Declaring and checking type of variable.

How to take the value for Python Numeric Data Types as an input from the user?

In above all the example, we have assigned a value to the variable. We can also ask the user to enter the numeric value and then store in a variable.

Steps followed for reading user input:

Taking user input. The input taken from the user is always considered as a string.

For taking the numeric value as a user input, we have to convert it into the numeric value.

I am complete Python Nut, love Linux and vim as an editor. I hold Master of Computer Science from NIT Trichy. I dabble in C/C++, Java too. I keep sharing my coding knowledge and my own experience on CSEstack Portal.