The isalpha() method is one of the inbuilt String methods of Python. The isalpha() function is used to check whether a string consists only of alphabets(a-z or A-Z) or not. In isalpha() function both uppercase and lowercase alphabets are allowed.
Python String isalpha() method Syntax :
string.isalpha()
Here, the string can be any string enclosed in double quotes or a string variable.
The return value of the Python String isalpha() method :
The isalpha() also returns True or False. It returns True if the string only consists of alphabets otherwise returns False.
Let’s understand with the help of some examples :
Example 1:
str = "Aabc"
print(str.isalpha())
Output :
True
Example 2:
str = "Aabc12"
print(str.isalpha())
Output :
False
Example 3:
str = " Aabc "
print(str.isalpha())
Output :
False
The above output is False because the above string contains space with characters.
Example 4:
str = "A@bc"
print(str.isalpha())
Output :
False