Python String isidentifier ()

Metoda isidentifier () vrne True, če je niz veljaven identifikator v Pythonu. Če ne, se vrne False.

Sintaksa isidentifier()je:

 string.isidentifier ()

isidentifier () Paramterji

isidentifier()Metoda ne sprejme nobenih parametrov.

Vrnjena vrednost iz isidentifier ()

V isidentifier()postopek vrne:

  • True, če je niz veljaven identifikator
  • Neustrezno, če niz ni neveljaven identifikator

Primer 1: Kako deluje isidentifier ()?

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

Izhod

 True False False False

Obiščite to stran, če želite izvedeti, kaj je veljaven identifikator v Pythonu?

Primer 2: Več Primer isidentifikatorja ()

 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.')

Izhod

root33 je veljaven identifikator. 33root ni veljaven identifikator. root 33 ni veljaven identifikator.

Zanimive Članki...