A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/python/python_cmath_pi_constant.htm below:

Python cmath.pi Constant

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4