The isalpha method will return True if all the characters of the string are alphabetic; otherwise, it returns False. If the string is empty, then the isalpha method will return False.
isalphawill returnTrueif all the characters of the string are defined in theCategory of the Unicode character Database. Refer here for Unicode Character categories. LetterLetter (L): lowercase (Ll), titlecase (Lt), uppercase (Lu), modifier (Lm), other (Lo)
string.isalpha()
True: If all the characters of the string are alphabetic.
False: If any one of the characters of the string is not alphabetic or if the string is an empty string.
string = "text"print(string.isalpha())#isalpha returns false because string has numbersstring = "ab3"print(string.isalpha())#isalpha returns false because the string has spacesstring = "I have space"print(string.isalpha())#for empty string isalpha returns falsestring = ""print(string.isalpha());
In the code above:
We call isalpha on the text string. The isalpha will return True because all the characters of the string are alphabetic.
We call isalpha on the ab3 string. The isalpha will return False because the string contains a numerical character.
We call isalpha on the I have space string. The isalpha will return False because the string contains a space character.
We call isalpha on the empty string. For the empty string, the isalpha method will return False.