Isidentifier() Method Of Str Class

Method Name:

isidentifier

Method Signature:

isidentifier ()

 

Method Overview:

  • isidentifier() method checks whether the contents of the string object forms a valid identifier as per Python syntax rules.

 

  • Returns, True if the contents of the string qualifies as a Python identifier. False otherwise.

 

 

Example:

# starts with digit

id1     = "1_name"

idCheck = id1.isidentifier()

print(idCheck)

 

# starts with digit and contains special characters

id2     = "1_name#"

idCheck = id2.isidentifier()

print(idCheck)

 

# starts with alphabet and contains special characters

id3     = "name#"

idCheck = id3.isidentifier()

print(idCheck)

 

# starts with alphabet, contains underscore and digit

id4     = "name_1"

idCheck = id4.isidentifier()

print(idCheck)

 

Output:

False

False

False

True


Copyright 2018 © pythontic.com