In Python, isalpha() is a built-in method used for string handling.
The isalpha() methods returns “True” if all characters in the string are alphabets, Otherwise, It returns “False”.
This function is used to check if the argument includes only alphabet characters (mentioned below).
string.isalpha() Parameters: isalpha() does not take any parameters Returns : 1.True- If all characters in the string are alphabet. 2.False- If the string contains 1 or more non-alphabets.
Input : string = 'Ayush' Output : True Input : string = 'Ayush Saxena' Output : False Input : string = 'Ayush0212' Output : False
True False False
Errors and Exceptions
- It contains no arguments , therefore an error occurs if a parameter is passed
- Both uppercase and lowercase alphabets return “True”
- Space is not considered to be alphabet, therefore it returns “False”
Application : Given a string in python, count number of alphabets in the string and print the alphabets.
Input : string = 'Ayush Saxena' Output : 11 AyushSaxena Input : string = 'Ayush0212' Output : 5 Ayush
1. Initialise a new string and variable counter to 0.
2. Traverse the given string character by character upto its length, check if character is an alphabet.
3. If it is an alphabet, increment the counter by 1 and add it to a the new string, else traverse to the next character.
4. Print the value of the counter and the new string.
11 AyushSaxena 5 Ayush
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python String Methods | Set 2 (len, count, center, ljust, rjust, isalpha, isalnum, isspace & join)
- numpy string operations | isalpha() function
- Python | Pandas Series.str.isalpha()
- Python String isspace() and its application
- Python String isdigit() and its application
- Python String isnumeric() and its application
- Build an Application to Search Installed Application using Python
- divmod() in Python and its application
- isprintable() in Python and its application
- Login Application and Validating info using Kivy GUI and Pandas in Python
- Profile Application using Python Flask and MySQL
- Build an Application to extract URL and Metadata from a PDF using Python
- Python String index() and its applications
- Birthday Reminder Application in Python
- Python | Create simple animation for console-based application
- English dictionary application using Python
- Python | ToDo GUI Application using Tkinter
- Hierarchical treeview in Python GUI application
- Create First GUI Application using Python-Tkinter
- GUI chat application using Tkinter in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : roozbeh