This is R FAQ 7.31 translated into Python:

http://www.hep.by/gnu/r-patched/r-faq/R-FAQ_82.html

That example in python gives the same result:

>>> a = math.sqrt(2)
>>> a*a - 2
4.440892098500626e-16

The difference in your tangent example is also very, very small:

>>> math.tan(math.pi/4) - 1
-1.1102230246251565e-16

and is just accumulated through all the floating point operations involved in dividing by four and taking the tan of an angle.

Answer from Spacedman on Stack Overflow
🌐
Kanaries
docs.kanaries.net › topics › Python › python-pi
How to Write Pi in Python: math.pi, numpy.pi, scipy, and More – Kanaries
February 20, 2026 - The standard math.pi stores 15 significant decimal digits (IEEE 754 double-precision). For more digits, use mpmath: from mpmath import mp mp.dps = 1000 # 1000 decimal places print(mp.pi) ... import math radians = math.radians(90) # 1.5707963267948966 radians = 90 * math.pi / 180 # same result ...
Discussions

Finding a number up to n decimal places in Python. Also, is math.pi from python reliable? - Stack Overflow
However, if you try them with ... not all correct. Reason for this is that math.pi is float, which has limited precision. To actually calcute correct digits of pi to any precision you can use this code (taken from official Python documentation for decimal library... More on stackoverflow.com
🌐 stackoverflow.com
rounding - How can I make numbers more precise in Python? - Stack Overflow
I'm just learning the basics of Python at the moment and I thought that, as a learning exercise, I'd try writing something that would approximate the number "e". Anyway, it always gives the answer ... More on stackoverflow.com
🌐 stackoverflow.com
python - math.pi doesn't give me the good value - Stack Overflow
The value math.pi is a floating point value. It therefore has the same precision as any other ordinary floating point value in Python. Passing it to Decimal isn't going to cause it to magically guess what the value is intended to be, then fill in the missing digits for you. More on stackoverflow.com
🌐 stackoverflow.com
python - Print pi to a number of decimal places - Stack Overflow
Yes! the same code would work for more than 15 numbers after the decimal point if we have a higher precision on the value of Pi. The math library displays just 15 numbers after the decimal which is why I put that condition. Please let me know if you're aware of how we can obtain Pi with a higher ... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

What is math.pi in Python?
math.pi is Python’s floating-point approximation of the mathematical constant pi, approximately 3.14159.
🌐
pythonpool.com
pythonpool.com › home › tutorials › python math.pi: circle formulas and examples
Python math.pi: Circle Formulas and Examples
Is math.pi the same as numpy.pi?
Yes. Both math.pi and numpy.pi return the identical IEEE 754 double-precision float value: 3.141592653589793. Use math.pi for general scripts and numpy.pi when working with NumPy arrays.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Python › python-pi
How to Write Pi in Python: math.pi, numpy.pi, scipy, and More – ...
Can I use pi in Python without importing math?
Yes, you can use numpy.pi, scipy.constants.pi, or sympy.pi. However, math.pi is the simplest option since the math module is part of Python's standard library and requires no installation.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Python › python-pi
How to Write Pi in Python: math.pi, numpy.pi, scipy, and More – ...
🌐
Python Pool
pythonpool.com › home › tutorials › python math.pi: circle formulas and examples
Python math.pi: Circle Formulas and Examples
July 13, 2026 - math.pi is a floating-point approximation of the mathematical constant pi. The Python documentation defines it as pi to the available precision, which means it uses normal Python float precision rather than unlimited decimal precision.
🌐
Mpmath
mpmath.org
mpmath - Python library for arbitrary-precision floating-point arithmetic
mpmath implements a huge number of special functions, with arbitrary precision and full support for complex numbers: Elementary functions (sqrt, exp, log, trigonometric, hyperbolic and inverse functions); mathematical constants (pi, e, the golden ratio, Euler's constant gamma, Catalan's, Apery's, ...
🌐
Vicente Hernando
vhernando.github.io › calculate-pi-digits-python-high-precision
Calculate PI digits (arbitrary-precision) using Python - Vicente Hernando
#!/usr/bin/python3 # Calculate PI number using this formula: # x[n+1] = x[n] + sin(x[n]) # # x[n+1] = x[n] + x[n] + x[n]**3/fact(3) - x[n]**5/fact(5) + x[n]**7/fact(7) - x[n]**9/fact(9) + .... from decimal import getcontext, Decimal import sys if len(sys.argv) < 2: print('Not enough arguments') ...
Find elsewhere
🌐
Replit
replit.com › home › discover › how to use pi in python
How to use pi in Python | Replit
April 14, 2026 - The code demonstrates the standard way to work with pi in Python. Instead of defining your own, possibly less accurate, version of pi, you import the math module. This gives you access to math.pi, a floating-point constant that offers the necessary precision for reliable calculations.
🌐
Medium
jccraig.medium.com › baking-1000-digits-of-pi-from-3-small-lines-of-python-579da9c3bc49
Baking 1000 Digits of Pi from 3 Small Lines of Python | by John Clark Craig | Medium
July 31, 2023 - Baking 1000 Digits of Pi from 3 Small Lines of Python Python’s mpmath module is a powerful tool for high accuracy calculation that you should know You likely know that integers in Python can grow …
🌐
Runebook.dev
runebook.dev › en › docs › python › library › math › constants
python - When math.pi Isn't Enough: Exploring High-Precision and NumPy Constants
You'll need to manually define ... using a formula or just taking a very precise literal # A common way is to use the 'acos' (arc cosine) function, since acos(-1) is pi pi_precise = getcontext().acost('-1') print(f"Decimal PI ...
🌐
LabEx
labex.io › tutorials › python-how-to-use-pi-in-mathematical-operations-418866
How to use pi in mathematical operations | LabEx
Python provides pi as a pre-defined constant in the math module: import math ## Accessing pi print(math.pi) ## Outputs the precise value of pi
🌐
Bomberbot
bomberbot.com › python › calculating-pi-with-python-from-simple-approximations-to-advanced-algorithms
Calculating Pi with Python: From Simple Approximations to Advanced Algorithms - Bomberbot
June 20, 2025 - When aiming for high-precision pi calculations, several optimization techniques can significantly enhance performance: Arbitrary-precision arithmetic: Python's decimal module or third-party libraries like mpmath allow for calculations with arbitrary precision, crucial for computing pi to millions ...
🌐
Python Forum
python-forum.io › thread-7387.html
math.pi
i am curious where module math stores the value of pi. i have found where it tests it, but i cannot find where it sets constants like pi and e. the last 3 bits are 000 and are the first 3 bits of a run of 5 bits that are 00000 so the precision coul...
🌐
W3Schools
w3schools.com › python › ref_math_pi.asp
Python math.pi Constant
The math.pi constant returns the value of PI: 3.141592653589793.