Table of Contents
The isalpha() method returns True if all characters in the string are alphabets. If not, it returns False.
The syntax of isalpha()
is:
string.isalpha()
1. isalpha() Parameters
isalpha()
doesn’t take any parameters.
2. Return Value from isalpha()
The isalpha()
returns:
- True if all characters in the string are alphabets (can be both lowercase and uppercase).
- False if at least one character is not alphabet.
3. Example 1: Working of isalpha()
name = "Monica" print(name.isalpha()) # contains whitespace name = "Monica Geller" print(name.isalpha()) # contains number name = "Mo3nicaGell22er" print(name.isalpha())
Output
True False False
4. Example 2: Working of isalpha()
name = "MonicaGeller" if name.isalpha() == True: print("All characters are alphabets") else: print("All characters are not alphabets.")
Output
All characters are alphabets
Checkout these related String methods as well:
- Python isalnum()
- Python isnumeric()
- Python isdigit()
- Python isdecimal()
Related posts:
Python Program to Merge Mails
Python delattr()
Python Operators
Python Set remove()
Python String encode()
Python Program to Sort a Dictionary by Value
Python Program to Add Two Matrices
Converting String to Stream of chars
Python Program to Reverse a Number
Python help()
Python classmethod()
Python Program to Print Colored Text to the Terminal
Python String rindex()
String Initialization in Java
Python Exception Handling Using try, except and finally statement
Python Program to Extract Extension From the File Name
Python Program to Illustrate Different Set Operations
Java String to InputStream
Python String rstrip()
Python datetime
Python Program to Display Powers of 2 Using Anonymous Function
Python sorted()
Python Program to Merge Two Dictionaries
Python String strip()
Python Program to Remove Punctuations From a String
Python Program to Swap Two Variables
Python Program to Iterate Through Two Lists in Parallel
Python hash()
Python Dictionary
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Check if a String is a Palindrome in Java
Python Program to Check the File Size