×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

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
Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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