Home »
Python
math.log10() method with example in Python
Python math.log10() method: Here, we are going to learn about the math.log10() method with example in Python.
Submitted by IncludeHelp, on April 20, 2019
Python math.log10() method
math.log10() method is a library method of math module, it is used to get the base-2 logarithm of a number, it accepts a number and returns base-10 logarithm of the given number.
The method math.log10() gives more accurate result than the log(x, 10).
Note: If we provide anything else except a number, the method returns a TypeError – "TypeError: a float is required".
Syntax of math.log10() method:
math.log10(x)
Parameter(s):x – is the number whose base-10 logarithm to be calculated.
Return value: float – it returns a float value that is the base-10 logarithm of the number x.
Example:
Input:
x = 21
# function call
print(math.log10(x))
Output:
1.3222192947339193
Python code to demonstrate example of math.log10() method
# python code to demonstrate example of
# math.log10() method
# importing math module
import math
# Base-10 logarithm
x = 21
print("Base-10 logarithm of ", x, " is = ", math.log10(x))
x = 10.23
print("Base-10 logarithm of ", x, " is = ", math.log10(x))
Output
Base-10 logarithm of 21 is = 1.3222192947339193
Base-10 logarithm of 10.23 is = 1.0098756337121602