The isalpha() function in python helps to check whether all the characters of a string are alphabets or not. The function returns true if all the characters are alphabets (can be uppercase and lowercase) otherwise returns false.
string.isalpha()
The isalpha() doesn't take any parameters. This function does not allow any special chars( ()!#%&?) even spaces.
The isalpha() method also can identify the Unicode alphabets of other international languages. If the specified string is empty, then isalpha() returns False.
Input | Return Value |
---|---|
if all are alphabet | True |
if at least one is not an alphabet | False |
string = "python"
print(string.isalpha())
# contains whitespace
string = "Python programming"
print(string.isalpha())
# contains number
string = "123python"
print(string.isalpha())
Output:
True False False
string = "Programming"
if string.isalpha() == True:
print("All characters are alphabets")
else:
print("All characters are not alphabets.")
Output:
All characters are alphabets