all Python 3Strings (str)function
str.isdecimal
character checks
True if all characters are decimal digits (0–9); stricter than isdigit.
Syntax
s.isdecimal()
Of the trio isdecimal → isdigit → isnumeric this is the narrowest check, and the only one worth trusting before int(): True means every character is a decimal digit (Unicode category Nd) that int() can parse. Signs, dots and spaces are not in that set, so '-5' and ' 12' come back False — for signed or fractional input fall back to try/except ValueError.
Examples
print('123'.isdecimal()) # → True
print('²'.isdecimal()) # → False
print(''.isdecimal()) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy