- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
How to handle very large numbers in Python?
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.
a = 182841384165841685416854134135 b = 135481653441354138548413384135 print(a - b)
This will give the output −
- Related Articles
- How to multiply large numbers using Python?
- How to divide large numbers using Python?
- How to add/subtract large numbers using Python?
- How to Handle Large CSV files with Pandas?
- Print all 3 digit repeating numbers in a very large number in C++
- How to generate large random numbers in Java?
- How to handle an exception in Python?
- How to handle Python exception in Threads?
- How to handle frames in Selenium with python?
- How to handle frames in Selenium Webdriver in Python?
- How to stop default printing of large numbers in R?
- How expensive are Python dictionaries to handle?
- How to handle invalid arguments with argparse in Python?
- How to handle child windows in Selenium with python?
- Maximum element in a very large array using pthreads in C++