AppDividend
Latest Code Tutorials

# Python pi: How to use Pi in Python

Pi is a famous mathematical constant, defined as the ratio of the circumference to the diameter of a circle, and its value is 3.141592653589793. Another popular mathematical constant defined in the math module is e. It is called Euler’s number, and it is a base of the natural logarithm. Its value is 2.718281828459045.

## Python pi

Pi in Python is a math library constant that returns a value of 3.141592653589793. The math.pi constant is defined as the circumference ratio to the diameter of a circle. Mathematically pi is represented by the greek letter π.

### Syntax

`math.pi`

### Return Value

It returns a float value that is the value of the mathematical constant “PI“.

### Example

```import math

print('The value of pi is: ', math.pi)
```

#### Output

`The value of pi is:  3.141592653589793`

## Python Math Module

Almost all the most essential mathematical methods are defined in the math module of Python. These include trigonometric functions, logarithmic functions, angle conversion functions, representation functions, etc. Also, two mathematical constants are defined in the math module.

Another well-known mathematical constant defined in the math module is e. It is called Euler’s number, and it is base on the natural logarithm. Its value is 2.718281828459045.

The math module in Python contains functions for calculating various trigonometric ratios for the given angle. The functions (sin, cos, tan, etc.) need the angle in radians as an argument. We, on the other side, are using the angle in degrees.

The math module presents two angle conversion functions: degrees() and radians(), to convert the angle from degrees to radians and vice versa.

For example, the following code converts the angle of 30 degrees to radians and back (Note: π radians is equivalent to 180 degrees).

```import math

print(math.degrees(math.pi/6))
```

#### Output

`29.999999999999996`

These constants in Python math are used to put them into our calculations.

Sr.No. Constants & Description
1 pi

It returns the value of pi: 3.141592653589793

2 E

It returns the value of natural base e. e is 0.718282

3 tau

It returns the value of tau. tau = 6.283185

4 inf

It returns the infinite.

5 nan

It returns Not a number type.

That’s it for this tutorial.

This site uses Akismet to reduce spam. Learn how your comment data is processed.