O método isidentifier () retorna True se a string é um identificador válido em Python. Caso contrário, retorna False.
A sintaxe de isidentifier()
é:
string.isidentifier ()
Parâmetros isidentifier ()
O isidentifier()
método não leva nenhum parâmetro.
Valor de retorno de isidentifier ()
O isidentifier()
método retorna:
- Verdadeiro se a string for um identificador válido
- False se a string não for um identificador inválido
Exemplo 1: Como funciona o isidentifier ()?
str = 'Python' print(str.isidentifier()) str = 'Py thon' print(str.isidentifier()) str = '22Python' print(str.isidentifier()) str = '' print(str.isidentifier())
Resultado
Verdadeiro Falso Falso Falso
Visite esta página para saber o que é um identificador válido em Python?
Exemplo 2: Mais exemplo de 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.')
Resultado
root33 é um identificador válido. 33root não é um identificador válido. root 33 não é um identificador válido.