Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Python String isidentifier()
The isidentifier() method returns True if the string is a valid identifier in Python. If not, it returns False.
The syntax of isidentifier() is:
string.isidentifier()
isidentifier() Paramters
The isidentifier() method doesn't take any parameters.
Return Value from isidentifier()
The isidentifier() method returns:
- True if the string is a valid identifier
- False if the string is not a invalid identifier
Example 1: How isidentifier() works?
str = 'Python'
print(str.isidentifier())
str = 'Py thon'
print(str.isidentifier())
str = '22Python'
print(str.isidentifier())
str = ''
print(str.isidentifier())
Output
True False False False
Visit this page to learn what is valid identifier in Python?
Example 2: More Example of 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.')
Output
root33 is a valid identifier. 33root is not a valid identifier. root 33 is not a valid identifier.
Also Read:
Did you find this article helpful?