The isalpha() Function is used to check if all the letters in the String are alphabets or not.
i.e. The String should only consist of alphabets (A to Z or a to z). Any values other than that will not be considered.
x = "Hello" if x.isalpha(): print("All the letters in the String are alphabets") else: print("No! Not all the letters in the String are alphabets")
In the above code, we have declared a String 'Hello' that has alphabets only.
So, to check, if all the letters in the String are alphabets, we have used 'isalpha()' function.
if x.isalpha(): print("All the letters in the String are alphabets") else: print("No! Not all the letters in the String are alphabets")
And in this case, all the letters in the String are alphabets. So, we got the below output.
Similarly, let us look at the next example.
x = "Hello29" if x.isalpha(): print("All the letters in the String are alphabets") else: print("No! Not all the letters in the String are alphabets")
In the above code, we have declared a String 'Hello29' that has numbers other than alphabets.
So, to check, if all the letters in the String are alphabets, we have used 'isalpha()' function.
if x.isalpha(): print("All the letters in the String are alphabets") else: print("No! Not all the letters in the String are alphabets")
And in this case, all the letters in the String are alphabets. So, we got the below output.