CKTIS / Python
str.isdigit
Tests whether every character is a Unicode digit and the string is nonempty.
Version: Python 3.14; repository image, production runtime not attested
Syntax
s.isdigit()Tests whether every character is a Unicode digit and the string is nonempty.
Superscript digits can pass this test without qualifying as decimal digits for integer parsing.
The superscript two is a Unicode digit, but it is not a decimal digit. Consequently the two displayed predicates disagree and int cannot parse that character as decimal input.
assert "²".isdigit() and not "²".isdecimal() and not "".isdigit()
Examples
print("²".isdigit())
print("²".isdecimal())
Result
True False
The superscript two is a Unicode digit, but it is not a decimal digit. Consequently the two displayed predicates disagree and int cannot parse that character as decimal input.