Suppose we have a string representing an identifier. We have to check whether it is valid or not. There are few criteria based on which we can determine whether it is valid or not.
If all of these three are valid then only the string is valid identifier.
So, if the input is like id = "_hello_56", then the output will be True.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(s): if not s.isalpha() and s != '_': return False for ch in s[1:]: if not ch.isalnum() and ch != '_': return False return True id = "_hello_56" print(solve(id))