Python math.log() Method
Python math.log(x)The method takes one argument and returns the natural logarithm of x (base e).
Syntax
The syntax of the math.log() method is as follows:
math.log(x[, base])
Parameter Description:
- x-- Required. A number. If x is not a number, a TypeError is returned. If the value is 0 or negative, a ValueError is returned.
- base-- Optional. The base, default is e.
Return Value
Returns a float, representing the natural logarithm of a number.
Example
The following example returns the natural logarithm of a number:
Example
# Import the math package
import math
# Output the natural logarithm of a number
print(math.log(2.7183))
print(math.log(2))
print(math.log(1))
import math
# Output the natural logarithm of a number
print(math.log(2.7183))
print(math.log(2))
print(math.log(1))
Output Result:
1.0000066849139877 0.6931471805599453 0.0Other Extensions
Python math Module