# How to multiply large numbers using Python?

PythonProgrammingServer Side Programming

You can multiply 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.

For example,

a = 15421681351
b = 6184685413848
print(a * b)


This will give the output −

95378247708541418748648

Published on 20-Apr-2018 11:59:23