Python - String isidentifier() Method


Advertisements

The 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.

Example:

In the below example, isidentifier() checks whether the string is a valid identifier or not.

MyString = "Hello World!"
print(MyString.isidentifier())

MyString = "Hello_World_123"
print(MyString.isidentifier())

Output

False

True

String Methods
Advertisements