Home » Python

math.log1p() method with example in Python

Python math.log1p() method: Here, we are going to learn about the math.log1p() method with example in Python.
Submitted by IncludeHelp, on April 20, 2019

Python math.log1p() method

math.log1p() method is a library method of math module, it is used to get the natural logarithm of 1+x (base e), it accepts a number and returns the natural logarithm of 1+number on base e.

Note: If we provide anything else except a number, the method returns a TypeError – "TypeError: a float is required".

Syntax of math.log1p() method:

    math.log1p(x)

Parameter(s):x – is the number whose logarithm to be calculated.

Return value: float – it returns a float value that is the natural logarithm of 1 + x.

Example:

    Input:
    x = 21

    # function call
    print(math.log1p(x))

    Output:
    3.091042453358316

Python code to demonstrate example of math.log1p() method

# python code to demonstrate example of 
# math.log1p() method

# importing math module
import math

# log1p()
x = 21
print("Natural logarithm of 1 +", x, " is = ", math.log1p(x))

x = 10.23
print("Natural logarithm of 1 +", x, " is = ", math.log1p(x))

Output

Natural logarithm of 1 + 21  is =  3.091042453358316
Natural logarithm of 1 + 10.23  is =  2.418588768750352


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.