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
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.