all Python 3Strings (str)function
str.isdigit
character checks
True if all characters are digits (including superscripts like ²).
Syntax
s.isdigit()
The accepted set is wider than isdecimal's: superscripts and circled digits pass, yet int() raises ValueError on them. That makes isdigit a poor guard before converting to a number — when the real question is whether int(s) will work, use isdecimal or just try/except.
Examples
print('123'.isdigit()) # → True
print('²'.isdigit()) # → True
print('12.3'.isdigit()) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy