CKTIS / Python
str.isdigit
Teste si un texte non vide ne contient que des chiffres Unicode. ² est un chiffre mais pas un chiffre décimal : isdigit donne True et isdecimal False.
Version : Python 3.14; repository image, production runtime not attested
Syntaxe
s.isdigit()Teste si un texte non vide ne contient que des chiffres Unicode. ² est un chiffre mais pas un chiffre décimal : isdigit donne True et isdecimal False.
Le test positif ne garantit donc pas une entrée valide pour int.
assert "²".isdigit() and not "²".isdecimal() and not "".isdigit()
Exemples
print("²".isdigit())
print("²".isdecimal())
Résultat
True False
Le test positif ne garantit donc pas une entrée valide pour int.