Python math.log1p() Method
Python math.log1p(x) The method returns the natural logarithm of 1+x (base e).
Syntax
The syntax of the math.log1p() method is as follows:
math.log1p(x)
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.
Return Value
Returns a floating-point number float representing the natural logarithm of 1+x.
Example
The following example returns the natural logarithm of 1+x:
Example
Import the math package
import
math
Output the natural logarithm of 1+x
(
math
.
log1p
(
2.7183
)
)
(
math
.
log1p
(
2
)
)
(
math
.
log1p
(
1
)
)
Output result:
1.313266574586334
1.0986122886681098
0.6931471805599453
Python math Module