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 Get Current time
Python Program to Iterate Through Two Lists in Parallel
Python Program to Display Powers of 2 Using Anonymous Function
Python Program to Remove Duplicate Element From a List
Python Program to Print the Fibonacci sequence
Python Program to Swap Two Variables
Intelligent Projects Using Python - Santanu Pattanayak
Python if...else Statement
Python Matrices and NumPy Arrays
Python Program to Find the Factorial of a Number
Python String index()
Python chr()
Deep Learning in Python - LazyProgrammer
Python String lower()
Python Dictionary copy()
Python Program to Solve Quadratic Equation
Python Program to Find HCF or GCD
Python globals()
Python Dictionary popitem()
Python Numbers, Type Conversion and Mathematics
Python Program to Split a List Into Evenly Sized Chunks
Python Program to Find Factorial of Number Using Recursion
Split a String in Java
Python Set symmetric_difference()
Python type()
Python Program to Concatenate Two Lists
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python range()
Python time Module
Python Program to Check Armstrong Number
Python Set add()
Python List pop()