Python math.log10() - Logarithm to Base 10
Python math.log10()
math.log10(x) function returns the logarithm of x to base 10.
Syntax
The syntax to call log10() function is
math.log10(x)
where
Parameter | Required | Description |
---|---|---|
x | Yes | A numeric value. The value must be greater than 0. |
If x is an invalid value, such as a negative value, then log10() raises ValueError.
Examples
In the following program, we find the logarithm of 10000 to base 10, using log10() function of math module.
Python Program
import math
x = 10000
result = math.log10(x)
print('log10(x) :', result)
Output
log10(x) : 4.0
Logarithm of a negative number to base 10.
Python Program
import math
x = -1
result = math.log10(x)
print('log10(x) :', result)
Output
ValueError: math domain error
Logarithm of infinity to base 10.
Python Program
import math
x = math.inf
result = math.log10(x)
print('log10(x) :', result)
Output
log10(x) : inf
Logarithm of decimal value to base 10.
Python Program
import math
x = 0.001
result = math.log10(x)
print('log10(x) :', result)
Output
log10(x) : -3.0
Summary
In this Python Examples tutorial, we learned the syntax of, and examples for math.log10() function.