The isidentifier() Function is used to check if the String is a valid identifier.
x = "24A"
if x.isidentifier():
print("Is an Identifier")
else:
print("Is not an Identifier")
In the above code, we have declared a String '24A' which is not an Identifier.
Function1.png)
Now, to check, if the String is an Identifier, we have used 'isidentifier( )' function.
if x.isidentifier():
print("Is an Identifier")
else:
print("Is not an Identifier")
And in this case, '24A' is not an Identifier. So, we got the below output.
Similarly, let us look at the next example.
x = "first_number"
if x.isidentifier():
print("Is an Identifier")
else:
print("Is not an Identifier")
In the above code, we have declared a String 'first_number' which is an Identifier.
Function2.png)
Now, to check, if the String is an Identifier, we have used 'isidentifier()' function.
if x.isidentifier():
print("Is an Identifier")
else:
print("Is not an Identifier")
And in this case, 'first_number' is an Identifier. So, we got the below output.