Identifikátor řetězce Pythonu ()

Metoda isidentifier () vrací True, pokud je řetězec platným identifikátorem v Pythonu. Pokud ne, vrátí False.

Syntaxe isidentifier()je:

 string.isidentifier ()

isidentifier () Parametry

isidentifier()Metoda nebere žádné parametry.

Návratová hodnota z isidentifier ()

Tyto isidentifier()metoda vrátí:

  • True, pokud je řetězec platným identifikátorem
  • False, pokud řetězec není neplatný identifikátor

Příklad 1: Jak funguje isidentifier ()?

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

Výstup

 True False False False

Na této stránce se dozvíte, co je platný identifikátor v Pythonu?

Příklad 2: Další příklad 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.')

Výstup

root33 je platný identifikátor. Kořen 33root není platný identifikátor. root 33 není platný identifikátor.

Zajímavé články...