CKTIS / Python
str.isdigit
Verifica se um texto não vazio contém apenas algarismos Unicode. ² é um algarismo mas não decimal: isdigit dá True e isdecimal dá False.
Versão: Python 3.14; repository image, production runtime not attested
Sintaxe
s.isdigit()Verifica se um texto não vazio contém apenas algarismos Unicode. ² é um algarismo mas não decimal: isdigit dá True e isdecimal dá False.
O teste positivo não garante uma entrada válida para int.
assert "²".isdigit() and not "²".isdecimal() and not "".isdigit()
Exemplos
print("²".isdigit())
print("²".isdecimal())
Resultado
True False
O teste positivo não garante uma entrada válida para int.