Python log10

The Python log10 math function calculates the logarithmic value of a given number of base 10. This log10 function is more accurate than math.log(x, 10). The syntax of the math log10 Function is

math.log10(number);

Number: A valid numeric expression and

  • If the number argument is a positive number, the log10 function returns the output.
  • If the number argument is a Zero or a Negative number, it returns ValueError.
  • And if it is not a number, it returns TypeError.

Python log10 Function Example

The log10 Function calculates the logarithmic value of a given number to base 10. In this example, we find the base 10 logarithmic value of different data types and display the output. Please refer to the Python Math functions article from our Python basics page.

  1. Within the first two statements, We used the Python log10 Function directly on Positive integer and Decimal values.
  2. Next two statements, We used it on Python Tuple and Python List items. If you observe the above Python screenshot, this Math function calculates the logarithm value of base 10.
  3. In the next statement, We tried it directly on multiple values
  4. Next, We tried on the String value, and log10 returns TypeError: a float is required.
  5. We tried on Negative value, and the math.log10 is returning ValueError: math domain error.
  6. Last, we tried on zero value. It is returning a ValueError: math domain error. Please refer to the logarithm article to understand the log function. Please refer to the Python exp, Python log2 (base 2 log value), and Python log1p functions.
import math

Tup = (1, 2, 3, -4 , 5) # Tuple Declaration
Lis = [-1, 2, -3.5, -4 , 5] # List Declaration

print('Logarithm value of Positive Number = %.2f' %math.log10(1))
print('Logarithm value of Positive Decimal = %.2f' %math.log10(2.5))

print('Logarithm value of Tuple Item = %.2f' %math.log10(Tup[2]))
print('Logarithm value of List Item = %.2f' %math.log10(Lis[4]))

print('Logarithm value of Multiple Number = %.2f' %math.log10(2 + 7 - 5))
print('Logarithm value of String Number = ', math.log10('Hello'))
LOG10 Function