# How to use math.log Function in Python

## Table of Contents

Python is a popular programming language for scientific computing and mathematics because it is easy to learn and easy to use.

A common function in mathematics is the log function, which allows you to compute the logarithm of a number.

In this post, we'll learn how to use the log function in Python.

## How to use the log function

Thankfully, Python has a built-in function for the log function.

Python offers users the `math`

module that contains many useful mathematical functions and constants.

Included in this module is the `log()`

function which we'll use to compute the logarithm of a number.

Simply import the `math`

module and use the `log()`

function.

```
PYTHONimport math
results = math.log(2);
print(results);
```

```
BASH0.6931471805599453
```

If you want to calculate the logarithm base 2 of a number, you can use the `log2()`

function.

```
PYTHONimport math
results = math.log2(2);
print(results);
```

```
BASH1.0
```

If you want to calculate the logarithm base 10 of a number, you can use the `log10()`

function.

```
PYTHONimport math
results = math.log10(1000);
print(results);
```

```
BASH3.0
```

Alternatively, you can just pass in your own base, and the log function will take care of the rest.

```
PYTHONimport math
results = math.log(25, 5);
print(results);
```

```
BASH2.0
```

In this case, the first parameter is the number you want to take the logarithm of, and the second parameter is the base of the logarithm.

## Conclusion

In this post, we learned how to use the log function in Python.

Simply import the `math`

module and that gives you access to all the log functions including `log2()`

, `log10()`

, and `log()`

.

Thanks for reading and happy coding!

- Getting Started with TypeScript
- Getting Started with Express
- Getting Started with Electron
- Git Tutorial: Learn how to use Version Control
- Best Visual Studio Code Extensions for 2022
- How to deploy a Node app using Docker
- Using Puppeteer and Jest for End-to-End Testing
- Getting Started with Handlebars.js
- Getting Started with React
- Setting Up Stylus CSS Preprocessor
- Setting Up a Local Web Server using Node.js
- Using Axios to Pull Data from a REST API