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:
Why String is Immutable in Java?
Python Get Current time
Python type()
Python bin()
Python String splitlines()
Python Program to Check If a List is Empty
Converting String to Stream of chars
Python Program to Get a Substring of a String
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Tuple
Python File I/O Operation
Deep Learning in Python - LazyProgrammer
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python enumerate()
Python Global Keyword
Python frozenset()
Python if...else Statement
Java – Generate Random String
Python Multiple Inheritance
Convert String to Byte Array and Reverse in Java
Python Program to Display the multiplication Table
Python List
Python Inheritance
Python Program to Convert String to Datetime
Python Directory and Files Management
Python Program to Extract Extension From the File Name
Python pass statement
Python Program to Add Two Numbers
Python Input, Output and Import
Convert char to String in Java
Converting a Stack Trace to a String in Java
JavaScript Methods of RegExp and String