Python String isalpha() Method With Example

Python String isalpha

Now, we are going to learn about the isalpha method. If we wish to check whether or not, all the characters in the string are alphabets, we can make use of the isalpha method to achieve this. The isalpha method returns True, if all the characters in the string are alphabets, and false otherwise. Let’s have a look at a simple program, which demonstrates the same thing –

Python String isalpha() Method

As you can see, we have a string, in which, not all the characters are alphabetic. There are some numbers as well. For this reason, the output from the isalpha method comes out to be False.

Now, Let’s have a look at another case, in which all the characters in the string are alphabets. Let’s have a look at another program, which demonstrates the same thing.

As you can see now, in the above program, we have a simple string, and we know that all the characters in the string are alphabets. So, since we are using the isalpha method on the string, we get the output as True this time. You can try executing the program and observing the output as well.

So, at times, when we are required to check if all the characters in the string are alphabets or not, in such situations, we can make use of the isalpha method.