isalpha Python
In most cases, there may be need to check strings with alphabets only, like in name validation and so on. Python provides many built-in methods for string handling. The isalpha() method is one of them that returns True if all characters in the string are alphabets. If not, it returns False. This function basically checks if the arguments include only alphabetic letters (both uppercase and lowercase).
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
Syntax of isalpha
string.isalpha()
This method does not take any parameter. An error occurs if a parameter is passed.
Examples of isalpha()
The following example demonstrates the working of isalpha() method -
name = "Priska"
print(name.isalpha())
# contains whitespace
name = "Priska Kashyap"
print(name.isalpha())
# contains number
name = "Priska234232Kasyap"
print(name.isalpha())
The above code returns the following output -

As, you can show in the above example, it returns true only for alphabetic strings. The space is also not considered as alphabetic that's why returns false.
Filter non alphabetic characters using isalpha
This method can also be used to filter the non alphabetic characters. In the given example, we have taken a string that contain non-alphabetic characters. We have looped over the string and filtered the string using isalpha() method -
string='@Pri#22323ska3Kasy09ap'
count=0
newstring=""
for s in string:
if (s.isalpha()) == True:
count+=1
newstring+=s
print(count)
print(newstring)
The above code returns the following output -

Related Articles
Python Spell Checker ProgramPython remove punctuation from string
How to convert Excel to CSV Python Pandas
How to read data from excel file using Python Pandas
How to read data from excel file in Python
Python read JSON from URL requests
Python send mail to multiple recipients using SMTP server
How to generate QR Code in Python using PyQRCode
Python programs to check Palindrome strings and numbers
CRUD operations in Python using MYSQL Connector
Fibonacci Series Program in Python
Python File Handler - Create, Read, Write, Access, Lock File
Python convert XML to JSON
Python convert xml to dict
Python convert dict to xml