English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
If the string is a valid identifier in Python, the isidentifier() method returns True. If not, it returns False.
The syntax of isidentifier() is:
string.isidentifier()
The isidentifier() method does not take any parameters.
The isidentifier() method returns:
True if the string is a valid identifier
False if the string is not a valid identifier
str = 'Python' print(str.isidentifier()) str = 'Py thon' print(str.isidentifier()) str = ''22Python print(str.isidentifier()) str = '' print(str.isidentifier())
When running the program, the output is:
True False False False
Visit this page to learnWhat is a valid identifier in Python?
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.')
When running the program, the output is:
root33 Is a valid identifier. 33root is not a valid identifier. root 33 Is not a valid identifier.