Python math.log1p() - Natural Logarithm of (1 + x)
Python math.log1p()
math.log1p(x) function returns the natural logarithm of (x + 1).
Syntax
The syntax to call log1p() function is
math.log1p(x)
where
Parameter | Required | Description |
---|---|---|
x | Yes | A numeric value. The value must be greater than -1. |
If x is an invalid value, such as -5 (less than -1), then log1p() raises ValueError.
Example
In the following program, we find the natural logarithm of (5 + 1), using log1p() function of math module.
Python Program
import math
x = 5
result = math.log1p(x)
print('log1p(x) :', result)
Output
log1p(x) : 1.791759469228055
Summary
In this Python Examples tutorial, we learned the syntax of, and examples for math.log1p() function.