The math.log()
function returns the logarithm of a given number to the specified base.
math.log(x, base)
Where, x
is the argument to which the logarithm is to be found. The optional base
argument specifies the base of the logarithm.
If the base is not given, the function returns the natural logarithm( to the base of e) of the given number.
Examples With Base Given
A logarithm is the power to which a number must be raised to get some other number. Since a negative number cannot be expressed as a power of a positive base, the logarithm of a negative number is undefined . A ValueError
is raised if the argument given to math.log()
function is negative.