math.log
Calculate the logarithm of a number: natural or to the given base.
Python 3.13
math.log(x[, base])- [ ]optional part
- x
- A positive number.int | float
- base
- The base of the logarithm; the number e if not given.int | floatOptional
Return value
A float; raises ValueError for zero and negative numbers.
Examples
Natural logarithm
Python 3.13
import math
print(math.log(10))2.302585092994046
Base-2 logarithm
Python 3.13
import math
print(math.log(8, 2))3.0
Details
For bases 2 and 10, the separate functions math.log2 and math.log10 are more accurate.
