String Methods
isdigit()
Check whether every character is a digit, including some special digit characters.
str.isdigit()
Check whether every character is a digit, including some special digit characters.
Result
Returns
True when the string is non-empty and all characters are digits; otherwise False.
Run it
Try it
Run it and change it
text = "²" print(text.isdigit())
Output
Press Run to see what it prints.Worth knowing
isdigit()accepts more characters thanisdecimal(), such as superscript 2.isnumeric()accepts an even wider set.