La méthode isidentifier () renvoie True si la chaîne est un identifiant valide en Python. Sinon, il renvoie False.
La syntaxe de isidentifier()
est:
string.isidentifier ()
Paramètres isidentifier ()
La isidentifier()
méthode ne prend aucun paramètre.
Valeur renvoyée par isidentifier ()
La isidentifier()
méthode renvoie:
- Vrai si la chaîne est un identifiant valide
- Faux si la chaîne n'est pas un identifiant invalide
Exemple 1: Comment fonctionne isidentifier ()?
str = 'Python' print(str.isidentifier()) str = 'Py thon' print(str.isidentifier()) str = '22Python' print(str.isidentifier()) str = '' print(str.isidentifier())
Production
Vrai Faux Faux Faux
Visitez cette page pour savoir ce qu'est un identifiant valide en Python?
Exemple 2: Plus Exemple de isidentifier ()
str = 'root33' if str.isidentifier() == True: print(str, 'is a valid identifier.') else: print(str, 'is not a valid identifier.') str = '33root' if str.isidentifier() == True: print(str, 'is a valid identifier.') else: print(str, 'is not a valid identifier.') str = 'root 33' if str.isidentifier() == True: print(str, 'is a valid identifier.') else: print(str, 'is not a valid identifier.')
Production
root33 est un identifiant valide. 33root n'est pas un identifiant valide. root 33 n'est pas un identifiant valide.