Content · Programming · Python

Python math.pi, math.e, math.tau, math.inf, and math.nan

Use the standard mathematical constants pi, e, tau, infinity, and NaN.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

Use the standard mathematical constants pi, e, tau, infinity, and NaN.

What It Does and Why It Matters


math.pi, math.e and math.tau represent frequently used mathematical constants as floats. math.inf is positive infinity; math.nan is not-a-number and does not compare equal to itself. These constants are not arbitrary-precision decimal values.

Prefer math.isfinite(), math.isnan(), and math.isinf() over assumptions about special-value comparisons.

Step-by-Step Example


Start with the complete example below. Read the inputs and predict what the final print statement will show before you run it.

import math
print(round(math.pi, 5))
print(round(math.tau, 5))
print(math.isinf(math.inf))
print(math.isnan(math.nan))

How the Code Works


  • The imports make these standard-library tools available: math.
  • The print calls display the results. Compare these results with the method’s documented return type and the input used.

Expected output:

3.14159
6.28319
True
True

Each displayed line comes from the corresponding calculation or check. The output helps verify the return values before you adapt the example to your own input.

What to Notice


Pay attention to the accepted input types, the returned value and the boundary behavior. Predict what changes if you replace the example input with an empty, zero, negative or missing value, where that value is meaningful for this operation.

If the task uses a library function, inspect its documented exceptions and return type before reusing it inside a larger function.

Where You Would Use This


Use this in calculations, data summaries, simulations or validation when the numerical assumptions match the task. Check input domains, units and precision before interpreting a result. A single example output does not prove a statistical conclusion.

Practice Exercise


Calculate the circumference of a circle using math.tau.

Before running your edited example, write down the result you expect. Then test at least one valid boundary or deliberately invalid value, using appropriate exception handling where necessary.

Reference: official Python documentation for the complete API contract and version notes.

Common Beginner Mistakes


  • Testing a NaN value using equality, or treating math.inf like a finite maximum number.
  • Overlooking the documented condition: math.pi, math.e and math.tau represent frequently used mathematical constants as floats. math.inf is positive infinity; math.nan is not-a-number and does not compare equal to itself.

Key Takeaways


  • Use the standard mathematical constants pi, e, tau, infinity, and NaN.
  • math.pi, math.e and math.tau represent frequently used mathematical constants as floats.
  • Calculate the circumference of a circle using math.tau.
Share this resourceSend this page to someone who may find it useful.