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 pass statement
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python strftime()
How to get current date and time in Python?
Python zip()
Python String format()
Python exec()
Python List remove()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Program to Calculate the Area of a Triangle
Python Tuple index()
Python Set difference_update()
Python Program to Iterate Through Two Lists in Parallel
Python Closures
Python List count()
Python Program to Check Armstrong Number
Python Set union()
Python String isnumeric()
String Set Queries
Python Program to Find LCM
Python Package
Python Program to Check If a String Is a Number (Float)
Python Program to Copy a File
Python List pop()
String Initialization in Java
Python Program to Find HCF or GCD
Python Program to Find the Largest Among Three Numbers
Python String strip()
Python compile()
Python Program to Sort Words in Alphabetic Order
Java InputStream to String
Python String rstrip()