CKTIS / Python
str.isdigit
Verifica che il testo non vuoto contenga soltanto cifre Unicode. ² è una cifra ma non decimale: isdigit dà True e isdecimal False.
Versione: Python 3.14; repository image, production runtime not attested
Sintassi
s.isdigit()Verifica che il testo non vuoto contenga soltanto cifre Unicode. ² è una cifra ma non decimale: isdigit dà True e isdecimal False.
Il test positivo non garantisce un ingresso valido per int.
assert "²".isdigit() and not "²".isdecimal() and not "".isdigit()
Esempi
print("²".isdigit())
print("²".isdecimal())
Risultato
True False
Il test positivo non garantisce un ingresso valido per int.