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 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python String ljust()
Python setattr()
Python File I/O Operation
Python Program to Convert Celsius To Fahrenheit
Python String upper()
Python Set difference()
Python Set add()
Python Strings
Python Set union()
Python Dictionary update()
Python Program to Get File Creation and Modification Date
Python Type Conversion and Type Casting
Python String expandtabs()
Python Tuple count()
Java – Generate Random String
Python Dictionary
How to Remove the Last Character of a String?
Python frozenset()
Python Iterators
Java InputStream to String
Python Machine Learning - Sebastian Raschka
Python Program to Get the Last Element of the List
Python RegEx
Python Exception Handling Using try, except and finally statement
Python Program to Check Prime Number
Python Recursion
Python Program to Shuffle Deck of Cards
Python sleep()
Python Program to Find the Sum of Natural Numbers
Python Program to Delete an Element From a Dictionary
Python Functions