Python String isidentifier ()

Metoda isidentifier () vraća True ako je niz valjani identifikator u Pythonu. Ako nije, vraća se False.

Sintaksa isidentifier()je:

 string.isidentifier ()

isidentifier () Paramteri

isidentifier()Metoda ne poduzimati nikakve parametre.

Povratna vrijednost iz isidentifikatora ()

The isidentifier()metoda vraća:

  • Tačno ako je niz valjani identifikator
  • Netačno ako niz nije nevažeći identifikator

Primjer 1: Kako funkcionira identifikator ()?

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

Izlaz

 True False False False

Posjetite ovu stranicu da biste saznali koji je valjani identifikator u Pythonu?

Primjer 2: Još primjera identifikatora ()

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

Izlaz

root33 je valjani identifikator. 33root nije valjani identifikator. root 33 nije valjani identifikator.

Zanimljivi članci...