my_str.isidentifier())
Returns True if the string is an identifier. Otherwise returns False. my_str='_abc45'
print(my_str.isidentifier()) # Output is True
my_str='ab#cd'
print(my_str.isidentifier()) # Output is False ( # not allowed )
my_str='A_abc1234'
print(my_str.isidentifier()) # Output is True
my_str='pq?rs'
print(my_str.isidentifier()) # Output is False ( ? not allowed)
my_str='pq rs'
print(my_str.isidentifier()) # Output is False ( space not allowed)
my_str='12ab'
print(my_str.isidentifier())#Output is False( Can't start with number)
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.