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 Calendar
Deep Learning in Python - LazyProgrammer
Python Machine Learning - Sebastian Raschka
Python String translate()
Python String upper()
Python List pop()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Program to Convert Bytes to a String
Python String isalpha()
Python Closures
Python Multiple Inheritance
Python for Loop
Python String lower()
Python Set update()
Python Program to Find the Factorial of a Number
Python Program to Find ASCII Value of Character
Python Recursion
Python Program to Get a Substring of a String
Python Program to Convert Kilometers to Miles
Python Set difference()
Python type()
Python Set issuperset()
Python Program to Check Leap Year
Python round()
Python Program to Append to a File
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python strptime()
Deep Learning with Python - Francois Chollet
Python Program to Get the Class Name of an Instance
Python format()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi