In Python to check whether if a string contain only alphabets we use isalpha()
function on a string. isalpha()
function is built-in string function which will returns as boolean value.
This short tutorial we given example below how to check given string have only alphabet or not.
isalpha() - to check if character is an alphabet or not by return value as boolean (true if alphabet, else not)
str.isalpha():boolean
Return Value: Returns boolean. True if str contain only alphabet, False if str contain at least one none alphabet.
Example #1
text = "cambotutorial is for free everyone."
check = text.isalpha()
print("Is contain only alphabets? ", check)
Output
Is contain only alphabets? False
Return false because there is a full stop[.] and there are some space between each word.
Example #2
text = "cambotutorialForEveryone"
check = text.isalpha()
print("Is contain only alphabets? ", check)
Output
Is contain only alphabets? True
Return true because no space and none other characters beside alphabet.
Example #3
text = "contact@cambotutorial.com for everyone"
check = text.isalpha()
print("Is contain only alphabets? ", check)
Output
Is contain only alphabets? False
Return false because there are special characters @ . and space existing in stirng.
In this tutorial we simply learned how to know if a string contains only alphabets or not, within example above hope it will help to handle your task.
PythonAs the founder and passionate educator behind this platform, I’m dedicated to sharing practical knowledge in programming to help you grow. Whether you’re a beginner exploring Machine Learning, PHP, Laravel, Python, Java, or Android Development, you’ll find tutorials here that are simple, accessible, and easy to understand. My mission is to make learning enjoyable and effective for everyone. Dive in, start learning, and don’t forget to follow along for more tips and insights!. Follow him