Python String isalpha() Method
str.isalpha() returns True if the string is not empty and every character is a letter. Spaces, digits, hyphens and punctuation make it False.Use isalpha() when text should consist of letters only, such as a first name field or a code made of letters. It follows Unicode, so letters such as é or क count as letters, not just a-z. The sibling checks are isdigit() for digits and isalnum() for letters or digits.
| Syntax | text.isalpha() |
|---|---|
| Parameters | None |
| Returns | True if every character is a letter and the string is not empty, else False |
| Empty string | False |
| Counts as letters | Letters of any language, such as é, ß, 你 |
What counts as a letter
A letter is any character Unicode puts in a letter category. Digits, spaces, underscores and symbols are not letters.
for s in ["Asha", "Asha Rao", "abc123", "café", "", "o'neil"]:
print(repr(s), s.isalpha())Notice that "Asha Rao" is False because of the space, and so is "o'neil" because of the apostrophe.
Checking a name made of several words
Real names often contain spaces or hyphens, so a plain isalpha() rejects valid input. Remove the allowed separators first, or test word by word with split().
name = "Mary-Anne Smith"
cleaned = name.replace("-", "").replace(" ", "")
print(cleaned.isalpha())isalpha() compared with the other character checks
| Test string | `isalpha()` | `isdigit()` | `isalnum()` |
|---|---|---|---|
"abc" | True | False | True |
"123" | False | True | True |
"abc123" | False | False | True |
"abc 123" | False | False | False |
"" | False | False | False |
Examples you can run
Press Run, then edit the code and run it again.
Letters only or not
The basic behaviour, including spaces and the empty string.
print("Python".isalpha())
print("Python3".isalpha())
print("Py thon".isalpha())
print("".isalpha())Expected outputTrue
False
False
False
Validate a name typed by the user
An if statement decides between accepting and rejecting the text.
name = input("First name: ")
if name.isalpha():
print("Welcome,", name.title())
else:
print("Letters only, please.")Expected outputFirst name: asha
Welcome, Asha
Keep only the letters of a string
Combine isalpha() with a generator expression and join() to filter characters.
text = "Order #A-102, qty: 5"
letters = "".join(ch for ch in text if ch.isalpha())
print(letters)Expected outputOrderAqty
Letters from other languages
Unicode letters count, so accented names pass.
for s in ["José", "Zoë", "Müller", "Jo3"]:
print(s, s.isalpha())Expected outputJosé True
Zoë True
Müller True
Jo3 False
Common mistakes
Rejecting names with spaces
✗ Wrong
print("Asha Rao".isalpha())✓ Right
print(all(w.isalpha() for w in "Asha Rao".split()))Remove or allow separators before testing, or check each word.
Assuming the empty string passes
✗ Wrong
print("".isalpha())✓ Right
text = ""
print(text == "" or text.isalpha())Treat emptiness as its own case if you need to.
Forgetting to call the method
✗ Wrong
word = "Hi"
if word.isalpha:
print("letters")✓ Right
word = "Hi2"
if word.isalpha():
print("letters")
else:
print("not only letters")Add the parentheses: word.isalpha().
Python String isalpha() Method: questions people ask
How do I check if a string contains only letters in Python?
Use text.isalpha(). It returns True only if every character is a letter and the string is not empty.
Does isalpha() allow spaces?
No. A space is not a letter, so "hello world".isalpha() is False.
Does isalpha() work with non-English letters?
Yes. It uses Unicode, so "é".isalpha() and "你".isalpha() are both True.
Keep learning
Step-by-step lessons:
Python StringsPython String Methods
Related:
Python String isdigit() MethodPython String isalnum() MethodPython String split() MethodPython String join() Method
More in string methods:
Python String split() MethodPython String join() MethodPython String strip() MethodPython String lstrip() MethodPython String rstrip() MethodPython String replace() MethodPython String upper() MethodPython String lower() Method See all →