← Go Back

How to Calculate the Logarithm of a Number

To calculate log5 25:

>>> import math
>>> math.log(25, 5)
2.0

If the second argument is omitted, the logarithm with base e of the number passed as the first argument is calculated:

>>> math.log(1000)
6.907755278982137

To make log2 n and log10 25 there are specific and more precise functions:

>>> math.log2(1000)
9.965784284662087
>>> math.log10(1000)
3.0

math arithmetic-operations


🐍 You might also find interesting: