OKPEDIA PYTHON EN MATEMATICA

How to write Pi in python

In the python language the value of Pi (π) is assigned to the constant math.pi of the math library.

import math
math.pi

The constant math.pi contains the value 3.141592653589793.

It can be used directly in scripts, without having to manually assign the Pi value to a variable each time.

Examples

Example 1

This script calculates Pi divided by two.

import math
x=math.pi/2
print(x)

The result of the script is as follows:

1.5707963267948966

Example 2

This script multiplies Pi by two in the print statement

import math
print(math.pi*2)

The output result is the following:

6.283185307179586

https://how.okpedia.org/en/python/how-to-write-pi-in-python


Report an error or share a suggestion to enhance this page


Python Mathematics


FacebookTwitterLinkedinLinkedin