Python String isidentifier ()

Metoda isidentifier () returnează True dacă șirul este un identificator valid în Python. Dacă nu, returnează False.

Sintaxa lui isidentifier()este:

 string.isidentifier ()

isidentifier () Parametri

isidentifier()Metoda nu ia nici un parametru.

Valoare returnată de la isidentifier ()

În isidentifier()metoda returneaza:

  • Adevărat dacă șirul este un identificator valid
  • Fals dacă șirul nu este un identificator nevalid

Exemplul 1: Cum funcționează isidentifier ()?

 str = 'Python' print(str.isidentifier()) str = 'Py thon' print(str.isidentifier()) str = '22Python' print(str.isidentifier()) str = '' print(str.isidentifier())

Ieșire

 Adevărat Fals Fals Fals

Accesați această pagină pentru a afla ce este identificatorul valid în Python?

Exemplul 2: Exemplu mai mult 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.')

Ieșire

root33 este un identificator valid. 33root nu este un identificator valid. rădăcina 33 nu este un identificator valid.

Articole interesante...