Metoda isidentifier () zwraca wartość True, jeśli łańcuch jest prawidłowym identyfikatorem w Pythonie. Jeśli nie, zwraca False.
Składnia isidentifier()
to:
string.isidentifier ()
isidentifier () Paramters
isidentifier()
Metoda nie ma żadnych parametrów.
Wartość zwracana z isidentifier ()
Te isidentifier()
metody powraca:
- Prawda, jeśli ciąg jest prawidłowym identyfikatorem
- Fałsz, jeśli ciąg nie jest nieprawidłowym identyfikatorem
Przykład 1: Jak działa isidentifier ()?
str = 'Python' print(str.isidentifier()) str = 'Py thon' print(str.isidentifier()) str = '22Python' print(str.isidentifier()) str = '' print(str.isidentifier())
Wynik
True False False False
Odwiedź tę stronę, aby dowiedzieć się, jaki jest prawidłowy identyfikator w Pythonie?
Przykład 2: Więcej Przykład 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.')
Wynik
root33 to prawidłowy identyfikator. 33root nie jest prawidłowym identyfikatorem. root 33 nie jest prawidłowym identyfikatorem.