Python Tutorial Python Advanced Python Resources Python Libraries
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Python - String isidentifier() Method



The Python String 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

5