Python Glossary Русский

Python 3.11+sysfunction

sys.get_int_max_str_digits()

interpreter

Returns the digit limit for converting int to str and back; 4300 by default. Longer numbers raise ValueError instead of a result.

Syntax

sys.get_int_max_str_digits()

A frequent surprise in big-number tasks: int itself grows without bound, but print(2**20000) fails with ValueError 'Exceeds the limit (4300 digits)'. The limit is a DoS protection: converting a huge number to text takes quadratic time. 0 means no limit. Conversions with hex(), bin() and oct() are not limited.

Examples

import sys
print(sys.get_int_max_str_digits())  # → 4300
n = 2 ** 20000
print(n.bit_length())  # → 20001
try:
    print(n)
except ValueError as e:
    print(type(e).__name__)  # → ValueError
print(len(hex(n)))  # → 5003

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy