Python Glossary Русский

all Python 3cmathterm

cmath.pi

constants

The number π in the cmath module: a plain float with the same value as math.pi. Handy to avoid importing math for one constant.

Syntax

cmath.pi

Despite the module, it is a float, not a complex. Its value equals math.pi (== gives True), but it is a separate object: cmath.pi is math.pi is False, so never compare with is. See math.pi for details about the precision of π.

Examples

import cmath
import math
print(cmath.pi, type(cmath.pi).__name__)  # → 3.141592653589793 float
print(cmath.pi == math.pi)  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy