Python math.log() Method
Python math.log(x) With one argument, the method 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, defaults to e.
Return Value
Returns a floating-point number 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
(
math
.
log
(
2.7183
)
)
(
math
.
log
(
2
)
)
(
math
.
log
(
1
)
)
Output result:
1.0000066849139877
0.6931471805599453
0.0
Python math Module