Python has many inbuilt functions that can manipulate your inputs like string, integers, float e.t.c. Python isalpha() is one of them. It allows you to check whether there’s is alphabets in the string or not by returning boolean value true or false. In this entire tutorial, you will know how to implement isalpha() python function.
Examples of isalpha() python
Let’s know all the possible examples of isalpha() function in python. Please note that I have implemented all the examples on the Jupyter Notebook. You can do it on your IDEs but I advise you to do it in the notebook for a better understanding. You can run your Jupyter notebook using the below command on your terminal.
Example 1: Applying isalpha() on numeric characters
In this example, I have numeric characters in the string. And when I use isalpha() on it then I will get the false value.
string = "123456" print(string.isalpha())
Example 2: Applying isalpha() on alphabets only
Now let’s apply isalpha() on string with alphabets characters only. Execute the below lines of code.
string = "DataScienceLearner" print(string.isalpha())
When you will run the above code you will get the true output. But in the case of the string containing alphabets with space between then isalpha() function will return false as space is another character in programming.
string = "Data Science Learner" print(string.isalpha())
Example 3: Apply isalpha() on an alphanumeric string
Let’s apply isalpha() function on a string containing both combinations of alphabets and numeric characters. When you will run the below lines of code you will get false output.
string = "DataScienceLearner123" print(string.isalpha())
These are the examples of how to use isalpha() function in python. There can be much practical application of this function. And the most popular one is counting the number of alphabets in a given string. I hope this tutorial has cleared your query on how to use isaplha() method. If you have any doubt then you can contact us for more help.
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.