Table of Contents
The isidentifier() method returns True if the string is a valid identifier in Python. If not, it returns False.
The syntax of isidentifier() is:
string.isidentifier()
1. isidentifier() Paramters
The isidentifier() method doesn’t take any parameters.
2. Return Value from isidentifier()
The isidentifier() method returns:
- True if the string is a valid identifier
- False if the string is not a invalid identifier
3. Example 1: How isidentifier() works?
str = 'Python' print(str.isidentifier()) str = 'Py thon' print(str.isidentifier()) str = '22Python' print(str.isidentifier()) str = '' print(str.isidentifier())
Output
True False False False
Visit this page to learn what is valid identifier in Python?
4. Example 2: More Example of isidentifier()
str = 'root33' if str.isidentifier() == True: print(str, 'is a valid identifier.') else: print(str, 'is not a valid identifier.') str = '33root' if str.isidentifier() == True: print(str, 'is a valid identifier.') else: print(str, 'is not a valid identifier.') str = 'root 33' if str.isidentifier() == True: print(str, 'is a valid identifier.') else: print(str, 'is not a valid identifier.')
Output
root33 is a valid identifier. 33root is not a valid identifier. root 33 is not a valid identifier.
Related posts:
Python Program to Display the multiplication Table
Python ord()
Python Program to Get File Creation and Modification Date
Python Tuple count()
Python List count()
Python Program to Access Index of a List Using for Loop
Python File I/O Operation
Python Generators
Python Modules
Python Keywords and Identifiers
Python datetime
Python Program to Compute all the Permutation of the String
Python Errors and Built-in Exceptions
Python Set issubset()
String Initialization in Java
Python String rstrip()
APIs in Node.js vs Python - A Comparison
Python Tuple
Python *args and **kwargs
Python hasattr()
Python String istitle()
Python Program to Find Sum of Natural Numbers Using Recursion
Python super()
Python Set add()
Python Program to Print all Prime Numbers in an Interval
Python iter()
Python pow()
Python sorted()
Python set()
Python list()
Python Program to Count the Number of Digits Present In a Number
Python Program to Convert Bytes to a String