all Python 3mathterm
math.pi
constants
The mathematical constant π ≈ 3.141592653589793. Used in trigonometry and geometry.
Syntax
math.pi
It is the nearest double to the true π, so math.sin(math.pi) returns about 1.2e-16 rather than zero — comparing such results to zero with == is pointless, use math.isclose with an abs_tol. Every trigonometric function in the module takes radians: convert degrees with math.radians(), otherwise you get a silently wrong answer and no error at all. For a full turn there is math.tau, which equals 2π.
Examples
import math
print(math.pi) # → 3.141592653589793
print(2 * math.pi) # → 6.283185307179586
print(math.pi ** 2) # → 9.869604401089358
area = math.pi * 5**2
print(round(area, 2)) # → 78.54
print(math.tau / 2) # → 3.141592... (tau = 2*pi)
print(math.degrees(math.pi)) # → 180.0
See also
Open in the full glossarydocs.python.orgReport an inaccuracy