Metóda isidentifier () vráti True, ak je reťazec platným identifikátorom v Pythone. Ak nie, vráti hodnotu False.
Syntax isidentifier()
je:
string.isidentifier ()
isidentifier () parametre
isidentifier()
Metóda neberie žiadne parametre.
Návratová hodnota z identifikátora ()
Tieto isidentifier()
metóda vráti:
- True, ak je reťazec platným identifikátorom
- False, ak reťazec nie je neplatný identifikátor
Príklad 1: Ako funguje isidentifier ()?
str = 'Python' print(str.isidentifier()) str = 'Py thon' print(str.isidentifier()) str = '22Python' print(str.isidentifier()) str = '' print(str.isidentifier())
Výkon
Pravda False False False
Navštívte túto stránku a dozviete sa, čo je platný identifikátor v Pythone?
Príklad 2: Ďalší príklad izidentifikátora ()
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ýkon
root33 je platný identifikátor. Root nie je platný identifikátor. root 33 nie je platný identifikátor.