# Python math.pi Attribute

The Python programming language offers a module, `math`, that implements a torrent of mathematical methods such as trigonometry, inverse trigonometry and logarithmic functions.

In mathematics, the number π or `3.14159` or `22 / 7` is a mathematical constant that refers to the ratio of a circle’s circumference to its diameter. It is an irrational and non-terminating number used to calculate perimeters, surface areas, and volumes of various shapes such as circles, cylinders, cones, etc.

This article will discuss the `pi` value available in the `math` module.

## Syntax

``````math.pi
``````

### Parameters

Since it is a variable, it does not accept any parameters.

### Returns

Since it is a variable, it does not return anything like a method. It stores the value of the mathematical constant `π`.

## Example 1: Use `math.pi` to Get the Value of `π`

``````import math

print(math.pi)
``````

Output:

``````3.141592653589793
``````

## Example 2: Use `math.pi` to Get the Circumference and Area of a Circle

``````import math

def area(r):
return math.pi * r * r

def circumference(r):
return 2 * math.pi * r

r = 25
print(f"Circumference: {circumference(r)} units")
print(f"Area: {area(r)} sq. units")
``````

Output:

``````Circumference: 157.07963267948966 units
Area: 1963.4954084936207 sq. units
``````

The Python code above calculates the circumference and area of a circle with a radius `r`. The formula for circumference is `2 * π * r`, and for the area is `π * r * r`.

## Example 3: Use `math.pi` to Convert Degrees to Radians

``````import math

return degrees * math.pi / 180

``````

Output:

``````90 degrees = 1.5707963267948966 radians
``````

The formula to convert degrees to radians is as follows.

``````radians = degrees * (π / 180)
``````

The Python code above defines a method, `toRadians()`, that accepts an angle in degrees and, using the formula discussed above, it converts it to radians.

## Example 4: Use `math.pi` to Convert Radians to Degrees

``````import math

return radians * 180 / math.pi

``````

Output:

``````90 radians = 5156.620156177409 degrees
``````

The formula to convert radians to degrees is as follows.

``````degrees = (180 / π) * radians
``````

The Python code above defines a method, `toDegrees()`, that accepts an angle in radians and transforms the input into degrees using the formula we just discussed above.

Vaibhav is an artificial intelligence and cloud computing stan. He likes to build end-to-end full-stack web and mobile applications. Besides computer science and technology, he loves playing cricket and badminton, going on bike rides, and doodling.

## Related Article - Python Math

• Python math.pow() Method
• Python Math.erf() Method
• Python Math.erfc() Method
• Python Math.expm1() Method
• Python Math.fabs() Method
• Python Math.factorial() Method