# Python log() Functions to Calculate Logarithm With Examples [Latest]

Oct 24, 2022

Logarithms are used to depict and represent large numbers. The log is an inverse of the exponent. This article will dive into the Python log() functions. The logarithmic functions of Python help the users to find the log of numbers in a much easier and efficient manner.

## Understanding the log() functions in Python

In order to use the functionalities of Log functions, we need to import the `math` module using the below statement.

We all need to take note of the fact that the Python Log functions cannot be accessed directly. We need to use the `math` module to access the log functions in the code.

Syntax:

The `math.log(x)` function is used to calculate the natural logarithmic value i.e. log to the base e (Euler’s number) which is about 2.71828, of the parameter value (numeric expression), passed to it.

Example:

In the above snippet of code, we are requesting the logarithmic value of 2.

Output:

## Variants of Python log() Functions

The following are the variants of the basic log function in Python:

• log2(x)
• log(x, Base)
• log10(x)
• log1p(x)

### 1. log2(x) – log base 2

The `math.log2(x)` function is used to calculate the logarithmic value of a numeric expression of base 2.

Syntax:

Example:

Output:

### 2. log(n, Base) – log base n

The `math.log(x,Base)` function calculates the logarithmic value of x i.e. numeric expression for a particular (desired) base value.

Syntax:

This function accepts two arguments:

• numeric expression
• Base value

Note: If no base value is provided to the function, the math.log(x,(Base)) acts as a basic log function and calculates the log of the numeric expression to the base e.

Example:

Output:

### 3. log10(x) – log base 10

The `math.log10(x)` function calculates the logarithmic value of the numeric expression to the base 10.

Syntax:

Example:

In the above snippet of code, the logarithmic value of 15 to the base 10 is calculated.

Output:

### 4. log1p(x)

The `math.log1p(x)` function calculates the log(1+x) of a particular input value i.e. x

Note: math.log1p(1+x) is equivalent to math.log(x)

Syntax:

Example:

In the above snippet of code, the log value of (1+15) for the input expression 15 is calculated.

Thus, `math.log1p(15)` is equivalent to `math.log(16)`.

Output:

Python NumPy enables us to calculate the natural logarithmic values of the input NumPy array elements simultaneously.

In order to use the numpy.log() method, we need to import the NumPy module using the below statement.

Syntax:

The `numpy.log()` function accepts input array as a parameter and returns the array with the logarithmic value of elements in it.

Example:

Output:

## Conclusion

In this article, we have understood the working of Python Log functions and have unveiled the variants of the logarithmic function in Python.