Python String isalpha()
Python String isalpha() method returns True if each of the character in given string is only a alphabet letter (a-zA-Z).
If the string contains one or more characters that does not belong to alphabet group, then isalpha() returns False.
In this tutorial, we will learn the syntax and examples for isalpha() method of String class.
Syntax
The syntax of String isalpha() method in Python is
str.isalpha()
Examples
In this example, we will take a string 'abcdABC'
, and check if this string is alpha using str.isalpha()
method.
Python Program
x = 'abcdABC'
result = x.isalpha()
print(result)
Output
True
String contains non-alpha character
In this example, we will take a string 'abcd12'
, and check if this string is alpha using str.isalpha()
method. Since the string contains non-alphabet characters 1
and 2
, isalpha() returns False.
Python Program
x = 'abcd12'
result = x.isalpha()
print(result)
Output
False
Conclusion
In this Python Tutorial, we learned how to check if given string contains only alphabets, using String method – isalpha().