To get the value of pi when using the numpy module in Python, you can use the **pi** constant.

```
import numpy as np
print(np.pi)
#Output:
3.141592653589793
```

When working with different programming languages, the ability to use different mathematical constants easily is very useful for a number of different reasons.

The ability to be able to perform complex computations without having to implement a lot is valuable.

One such case is if you want to use the mathematical constant pi in Python.

You can get the value of pi using the numpy module. To get the value of pi when using the numpy module in Python, you can use the **pi** constant.

Below shows you how to use the numpy constant pi in Python.

```
import numpy as np
print(np.pi)
#Output:
3.141592653589793
```

## Difference between numpy.pi and math.pi in Python

Another way you can get the value of pi in Python is with the math module.

While both numpy.pi and math.pi provides us with the same value, the advantage of numpy.pi is that it helps us by avoiding the dependency of obtaining the constant value of pi from a different library.

Below shows you that the value of pi is the same if you use either numpy or math in Python.

```
import numpy as np
import math
print(np.pi)
print(math.pi)
#Output:
3.141592653589793
3.141592653589793
```

Hopefully this article has been useful for you to learn how to get the mathematical constant pi in your Python code when using numpy.

## Leave a Reply