Python – Find Natural Logarithm/Logarithm – log() Function with Examples

log() function is used to find the the natural logarithm of x (to base e in Python for the given input(x – parameter).

 

Syntax of log() Function

The syntax of log() function in Python is:

math.log(x[, base])

 

Parameters of log() Function in Python

x – Where x is any valid python number (positive or negative). This parameter is required.
Note: If the x parameter is not a number, log() function will return an Error.

 

Compatibility

log() function is available and compatible with both Python 2.x and 3.x. This function is a part of python standard math library.

 

Return Value of log() Function in Python

log() function returns the natural logarithm of x (to base e for the given input.

 

Python log() Function Example

# import math library
import math
print(math.log(-0.2))
print(math.log(0))
print(math.log(0.2))
print(math.log(77))
print(math.log(-3677))

Output: