isidentifier() String Method in Python with Examples

isidentifier() method returns True if the string is a valid Python identifier otherwise it returns False.

Example 1: isidentifier() String Method


message = 'area'

if message.isidentifier():
    print('"%s" is valid python identifier string.' %(message))
else:
    print('"%s" is not valid python identifier string.' %(message))

Output

"area" is a valid python identifier string.

Example 2: isidentifier() String Method


message = '1area'

if message.isidentifier():
    print('"%s" is a valid python identifier string.' %(message))
else:
    print('"%s" is not a valid python identifier string.' %(message))

Output

"1area" is not valid python identifier string.


Related String Methods