Python String isalpha() Method - GeeksforGeeks

12 Aug, 2021
Python String isalpha() method 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). 
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
Syntax: 
string.isalpha()
Parameters:
isalpha() does not take any parameters
Returns:
True: If all characters in the string are alphabet.
False: If the string contains 1 or more non-alphabets.
Errors and Exceptions:
It contains no arguments, therefore an error occurs if a parameter is passedBoth uppercase and lowercase alphabets return “True”Space is not considered to be the alphabet, therefore it returns “False”
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 the alphabet, therefore it returns “False”
Input : string = 'Ayush'
Output : True

Input : string = 'Ayush Saxena'
Output : False

Input : string = 'Ayush0212'
Output : False
Python3
# Python code for implementation of isalpha()   # checking for alphabetsstring = 'Ayush'print(string.isalpha())   string = 'Ayush0212'print(string.isalpha())   # checking if space is an alphabetstring = 'Ayush Saxena'print( string.isalpha())
Output: 
True
False
False
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
Algorithm:
Initialize a new string and variable counter to 0. Traverse the given string character by character upto its length, check if character is an alphabet. If it is an alphabet, increment the counter by 1 and add it to a the new string, else traverse to the next character. Print the value of the counter and the new string.
Initialize a new string and variable counter to 0. 
Traverse the given string character by character upto its length, check if character is an alphabet. 
If it is an alphabet, increment the counter by 1 and add it to a the new string, else traverse to the next character. 
Print the value of the counter and the new string.
Python3
# Python program to illustrate# counting number of alphabets # using isalpha()  # Given stringstring='Ayush Saxena'count=0  # Initialising new stringsnewstring1 =""newstring2 =""  # Iterating the string and checking for alphabets# Incrementing the counter if an alphabet is found# Finally printing the countfor a in string:    if (a.isalpha()) == True:        count+=1        newstring1+=aprint(count)print(newstring1)  # Given stringstring='Ayush0212'count=0for a in string:    if (a.isalpha()) == True:        count+=1        newstring2+=aprint(count)print(newstring2)
Output: 
11
AyushSaxena
5
Ayush
roozbeh
AmiyaRanjanRout
Python-Built-in-functions
python-string
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Read JSON file using Python
Adding new column to existing DataFrame in Pandas
Python map() function
How to get column names in Pandas dataframe
Python Dictionary
Taking input in Python
Read a file line by line in Python
How to Install PIP on Windows ?
Different ways to create Pandas Dataframe
Enumerate() in Python