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 only contains letters, numbers, and underscores (_), then the string is considered a valid identifier. Valid identifiers 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())