Python String isidentifier() Method
Example
Check if the string is a valid identifier:
txt = "Demo" x = txt.isidentifier() print(x)
Definition and Usage
If the string is a valid identifier, the isidentifier() method returns True, otherwise it returns False.
If the string contains only letters, numbers, and underscores (a-z, 0-9, _) and does not start with a number or contain any spaces, it is considered a valid identifier. A valid identifier cannot start with a number or contain any spaces.
Syntax
string.isidentifier()
Parameter Value
No parameters.
More Examples
Example
Check if the string is a valid identifier:
a = "MyFolder" b = "Demo002" c = "2bring" d = "my demo" print(a.isidentifier()) print(b.isidentifier()) print(c.isidentifier()) print(d.isidentifier())