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 Trim Whitespace From a String
Python Program to Differentiate Between del, remove, and pop on a List
Python Set intersection_update()
Python Generators
Python bytearray()
Python Program to Iterate Through Two Lists in Parallel
Python Program to Find Sum of Natural Numbers Using Recursion
CharSequence vs. String in Java
Python Program to Slice Lists
Python String istitle()
Python Program to Remove Duplicate Element From a List
Python String center()
Python Program to Print the Fibonacci sequence
Python Program to Check if a Key is Already Present in a Dictionary
Python while Loop
Python *args and **kwargs
Python globals()
Python strptime()
Python Tuple count()
Python Program to Convert Bytes to a String
Python abs()
Python complex()
Deep Learning with Python - Francois Chollet
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Program to Randomly Select an Element From the List
Python String endswith()
Python Program to Find Numbers Divisible by Another Number
Python bytes()
Python dir()
Python Inheritance
Python set()
Python Dictionary clear()