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

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.