Advertisement



< Prev
Next >



Python - String isidentifier() Method



The isidentifier() string method returns True if the string's value is a valid identifier in Python, otherwise it returns False.

Identifiers are the names given to variables, functions, classes, modules etc, by following some rules specified by Python. These rules are as follows :

Note : None of the string methods change the original string and only return a new string which reflects the change performed by the string method, hence the returned string must be stored or used(if needed to reflect the result), otherwise it is lost.



Signature of isidentifier()


The isidentifier() method has no parameters, so we don't have to worry about passing it some value.

# Signature of isidentifier() method 
isidentifier()





Let us see a few more examples of calling the isidentifier() method on all different forms of strings of valid and invalid identifiers.

# Python - Method isidentifier() Example



# Calling isidentifier() on a string of characters and digits i.e. a valid identifier
print('apple_price2'.isidentifier())


# Calling isidentifier() on a string of all upper case letters i.e. a valid identifier
print('ACTOR'.isidentifier())



# Calling isidentifier() on a string of all lower case values separated by space i.e. an invalid indentifier
print('The name'.isidentifier())



# Calling isidentifier() on a string of all lower case letters separated by dot i.e. an invalid identifier
print('the.address'.isidentifier())


Output is :


True
True
False
False





Please share this article -





< Prev
Next >
< String isdecimal() Method
String isprintable() Method >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement