Skip to content

Python math log10() function

  • by

Python math log10() function calculates the base-10 log of a number. Its input and convert it into a base 10 logarithmic.

math.log10(x)

You need to import the math module and then we need to call this function using the math static object.

Python math log10() function example

Simple example code Python log10 Return the base-10 logarithm of different numbers.

import math

print(math.log10(2.265))
print(math.log10(2))
print(math.log10(1))

Output:

Python math log10() function

A ValueError is returned if the number parameter is zero or a negative value.

    import math
    a = 0
    print(math.log10(a))

It returns a TypeError if it is not an integer.

 import math
    a = "Hello"
    print(math.log10(a))

What is the difference between log10 and log in Python?

Answer: According to the Python Math module documentation:

math.log(x,[base])
With one argument, return the natural logarithm of x (to base e). With two arguments, return the logarithm of x to the given base, calculated as log(x)/log(base).

math.log10(x)
Return the base-10 logarithm of x. This is usually more accurate than log(x, 10).

Do comment if you have any doubts or suggestions on this Python log topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading