Python String - isidentifier() Method
The Python isidentifier() method is used to check whether the string is a valid identifier or not. It returns true when the string is a valid identifier, else returns false.
A identifier must contain alphanumeric characters or underscores (_). Alphanumeric characters belongs to numbers 0 - 9, letters A - Z (both uppercase and lowercase). Along with this, a valid identifier must start with alphabet and should not contain any whitespaces.
string.isidentifier()
Parameters
No parameter is required.
Return Value
Returns True if the given string is a valid identifier, else returns False.
Example:
In the example below, isidentifier() checks whether the string is a valid identifier or not.
MyString = "Hello World!" print(MyString.isidentifier()) MyString = "Hello_World_123" print(MyString.isidentifier())
The output of the above code will be:
False True
❮ Python String Methods