- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

You can add/subtract 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 −

47359730724487546868440750000

- Related Questions & Answers
- How to multiply large numbers using Python?
- How to divide large numbers using Python?
- C++ Program to add few large numbers
- How to add binary numbers using Python?
- How to handle very large numbers in Python?
- Add grouping specifiers for large numbers in Java
- How to generate large random numbers in Java?
- How to add separator to numbers using MySQL views?
- Python program to add two numbers
- 8085 program to subtract two BCD numbers
- Large Fibonacci Numbers in C#
- Handling large numbers in C++?
- Add Two Numbers in Python
- 8051 Program to Subtract two 8 Bit numbers
- 8085 Program to Subtract two 8 Bit numbers

Advertisements