The log()
function in Python calculates the logarithm of a number to the base or calculates the natural logarithm of a number if the base is not specified by the user.
The following illustration shows the mathematical representation of the log()
function.
The
math
module is required in order to use this function.
log(number, base)
This function requires two parameters:
base
of the log()
returns the logarithm of a number to the base sent as a parameter.
Remember that the
log()
function calculates the natural logarithm of a number if the base is not provided, i.e.,log(y,e)
.
#Module requiredimport math#number without a baseprint "log(20) : ", math.log(20)#number with a baseprint "log(2,2) : ", math.log(2,2)