# How to handle very large numbers in Python?

PythonProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

You can perform arithmetic operations on large numbers in python directly without worrying about speed. Python supports a "bignum" integer type which can work with arbitrarily large numbers. In Python 2.5+, this type is called long and is separate from the int type, but the interpreter will automatically use whichever is more appropriate.

As long as you have version 2.5 or better, just perform standard math operations and any number which exceeds the boundaries of 32-bit math will be automatically (and transparently) converted to a bignum.

## example

a = 182841384165841685416854134135
b = 135481653441354138548413384135
print(a - b)

## Output

This will give the output −

47359730724487546868440750000
Updated on 05-Mar-2020 11:08:24