1000 digits of pi in Python

If you don’t want to implement your own algorithm, you can use mpmath.

try:
    # import version included with old SymPy
    from sympy.mpmath import mp
except ImportError:
    # import newer version
    from mpmath import mp

mp.dps = 1000  # set number of digits
print(mp.pi)   # print pi to a thousand places

Reference

Update: Code supports older and newer installations of SymPy (see comment).*

Leave a Comment