Python 3.11+sysfunction
sys.set_int_max_str_digits()
interpreter
Changes the digit limit for converting int to str and back (4300 by default); 0 removes it. Needed in tasks with very long numbers.
Syntax
sys.set_int_max_str_digits(maxdigits)
When a solution prints a huge factorial or Fibonacci number, put sys.set_int_max_str_digits(0) first — otherwise print or int(input()) raises ValueError. Values 1 to 639 are rejected: use 0 or at least 640. Older branches have the limit too (since 3.10.7, 3.9.14, 3.8.14 as a security fix), and it can be set from outside with PYTHONINTMAXSTRDIGITS or -X int_max_str_digits.
Examples
import math, sys
sys.set_int_max_str_digits(0)
s = str(math.factorial(2000))
print(len(s)) # → 5736
# Python 3.14+
import sys
try:
sys.set_int_max_str_digits(100)
except ValueError as e:
print(e) # → maxdigits must be >= 640 or 0 for unlimited
import sys
sys.set_int_max_str_digits(5000)
print(len(str(10 ** 4999))) # → 5000
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy