Menu Close

Python String isidentifier() Method

python string isidentifier

In this article, you will learn about the Python string isidentifier() method. Python isidentifier function is used to check a string contains a valid identifier or not.

In the previous tutorial, we have seen the Python string isdigit() method to check whether a string contains digits or not.

Python String isidentifier() Method:

The Python string identifier() function is a string built-in function that is used to check whether a string contains a valid identifier or not.
If the string contains a valid identifier, it will return True otherwise return False.

Syntax:

The syntax of the string isidentifier() method is:-

string.isidentifier()

Parameter:

The string isidentifier() method does not support any parameter.

Return Type:

The string isidentifier function return either True or False.

Python string isidentifier Example:

Here we will take some examples to understand python string isidentifier() method.

Example 1:

str = "Python"
str2 = str.isidentifier()
print(str2)

In above example output will be True because str contain valid identifier.

Exampe 2:

str = "$Programming"
str2 = str.isidentifier()
print(str2)

In above example output will be True because str contain valid identifier.

Example 3:

str = "12Python"
str2 = str.isidentifier()
print(str2)

In above example output will be False because identifier can not start with digits.

Conclusion:

In this tutorial, you have learned the Python string isidentifier() method to check a valid identifier or not.
If the string contains a valid identifier, Then the string isidentifier function returns True otherwise returns False.

I hope this tutorial will help you. if you like the string isidentifier function article, please share it with your friends who want to learn Python programming.

For More Information:- Click Here

Python String isdigit() Method
Python String isnumeric() Method

Related Posts