Python cmath.pi Constant



The Python cmath.pi constant is defined as the ratio of the circumference to the diameter of a circle. This is calculated mathematically using spheres, trigonometry, and other geometric computations.

This is denoted as Π(pi). This value is approximately equal to 3.14159. If you divide a circle's circumference by its diameter, then we will always get a Π.

This Π constant can't be expressed as a fraction because it is an irrational number, and its decimal representation goes on infinite without repeating.

syntax

Following is the basic syntax of the Python cmath.piconstant −

cmath.pi
cmath.pi

Return Value

This constant returns the value of pi, i.e., 3.14159.

Example 1

In the below example we are calculating the pi value using cmath.pi Constant.

import cmath
x = cmath.pi
print(x)

Output

Following is the output of the above code −

3.141592653589793

Example 2

In the following example, we are calculating the area of a circle using the cmath.pi constant.

import cmath
r = 4
area = cmath.pi * (r ** 2)
print("The area of a circle with radius", r, "is:", area)

Output

The result is produced as follows −

The area of a circle with radius 4 is: 50.26548245743669

Example 3

In this example, we are calculating the volume of a sphere using the cmath.pi constant.

import cmath
r = 5
volume = (4/3) * cmath.pi *(r ** 3)
print("The volume of the sphere with radius", r, "is:", volume)

Output

The output is obtained as follows −

The volume of the sphere with radius 5 is: 523.5987755982989

Example 4

Here, we are calculating the circumference of a circle using the cmath.pi constant.

import cmath
r = 8
circumference = 2 * cmath.pi * r
print("The circumference of the circle with radius", r, "is:", circumference)

Output

Following is the result −

The circumference of the circle with radius 8 is: 50.26548245743669
python_modules.htm
Advertisements
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy