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 Powers of 2 Using Anonymous Function
Python list()
How to get current date and time in Python?
Convert Character Array to String in Java
Python format()
Python Dictionary setdefault()
Python Program to Get the File Name From the File Path
Python RegEx
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python hash()
Python dict()
Python List index()
Python String isalnum()
Python filter()
Python bin()
Python len()
Python Decorators
Python String maketrans()
Python strptime()
Python Program to Convert Celsius To Fahrenheit
Python Program to Compute the Power of a Number
Python Program to Catch Multiple Exceptions in One Line
Python Program to Print Hello world!
Java – Reader to String
Python Data Structures and Algorithms - Benjamin Baka
Python Get Current time
Python Program to Trim Whitespace From a String
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Generate a Random Number
Python Program to Differentiate Between type() and isinstance()
Python String strip()
Python Program to Calculate the Area of a Triangle