The isidentifier Method: Checking if a String is a Python Identifier
Determines if a string is an identifier, returning True or False.
isidentifier()
This method checks if a string is a valid Python identifier. For more details on identifiers and keywords, see the original documentation section Identifiers and keywords.
'continue'.isidentifier() # True
'cat'.isidentifier() # True
'function_name'.isidentifier() # True
'ClassName'.isidentifier() # True
'_'.isidentifier() # True
'number1'.isidentifier() # True
'1st'.isidentifier() # False
'*'.isidentifier() # False
To determine if a string is a reserved keyword (e.g., def, class), use keyword.iskeyword().