str.isdigit
Check that the string is not empty and contains only digits.
Python 3.13
str.isdigit()Return value
True or False; False for an empty string.
Examples
Digits only
Python 3.13
print('2024'.isdigit())True
A minus sign is not a digit
Python 3.13
print('-5'.isdigit())False
Details
A minus sign and a decimal point are not digits, so "-5" and "3.14" give False. Superscript digits such as "²" do count, although int("²") raises ValueError.
