English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Se la stringa è un identificatore valido in Python, il metodo isidentifier() restituisce True. Se non lo è, restituisce False.
La sintassi di isidentifier() è:
string.isidentifier()
Il metodo isidentifier() non accetta alcun parametro.
Il metodo isidentifier() restituisce:
True se la stringa è un identificatore valido
False se la stringa non è un identificatore valido
str = 'Python' print(str.isidentifier()) str = 'Py thon' print(str.isidentifier()) str = '22Python' print(str.isidentifier()) str = '' print(str.isidentifier())
Quando si esegue questo programma, l'output è:
True False False False
Visita questa pagina per sapereCos'è un identificatore valido in Python?
str = 'root33' if str.isidentifier() == True: print(str, 'è un identificatore valido.') else: print(str, 'non è un identificatore valido.') str = '33root' if str.isidentifier() == True: print(str, 'è un identificatore valido.') else: print(str, 'non è un identificatore valido.') str = 'root 33' if str.isidentifier() == True: print(str, 'è un identificatore valido.') else: print(str, 'non è un identificatore valido.')
Quando si esegue questo programma, l'output è:
root33 è un identificatore valido. 33root non è un identificatore valido. root 33 non è un identificatore valido.