Python isalpha() Method

Definition
In Python, isalpha() returns True when every character is a letter and the string is not empty.
It takes no arguments. Digits, spaces, and punctuation make it return False.
Syntax
Call isalpha on the string. Start with this line.
| Call | What it does |
|---|
"Hello".isalpha() | Returns True. |
"Hello World".isalpha() | Returns False (space). |
An empty string always returns False.
Library declarations
Parameters
This method has no parameters.
Return Value
| Return Value | Description |
|---|
| bool | True if all characters are letters. |
Python Examples
Example 1 — Basic isalpha() Checks
See what passes and what fails.
samples = ["Python", "abc123", "Hi!", "a b", "", "café"]
for s in samples:
print(repr(s), "→", s.isalpha())
'Python' → True
'abc123' → False
'Hi!' → False
'a b' → False
'' → False
'café' → True
How It Works
- Letters pass.
"Python" is all alphabetic. - Digits fail. Any digit in
"abc123" returns False. - Symbols and spaces fail.
! and spaces break the rule. - Unicode letters can pass.
"café" counts as letters.
Example 2 — Validate a Name Token
Allow only letters after trimming outer spaces.
def is_letter_token(text):
cleaned = text.strip()
return cleaned != "" and cleaned.isalpha()
print(is_letter_token(" Ada "))
print(is_letter_token("Ada42"))
print(is_letter_token(" "))
How It Works
- Strip edges. Outer spaces are removed before the test.
- Require content. All-space input becomes
"" → reject. - isalpha decides.
"Ada" passes; digits fail. - Names with spaces. Full names need a different rule (split words, then check each).
Example 3 — isalpha vs isalnum
Same string, two different questions.
s = "abc123"
print("isalpha:", s.isalpha())
print("isalnum:", s.isalnum())
print("isdigit:", s.isdigit())
isalpha: False
isalnum: True
isdigit: False
How It Works
- isalpha rejects digits. Needs letters only →
False. - isalnum allows the mix. Letters + digits →
True. - isdigit rejects letters. Needs digits only →
False. - Pick by rule. Pure names →
isalpha; IDs → isalnum.
Frequently Asked Questions
It returns True if every character is a letter and the string is not empty.
False.
No. A space makes it False.
isalpha() requires letters only. isalnum() also allows digits.
Yes. Many non-ASCII letters can return True.
CODETOFUN NEWS
Stay Ahead in Tech
Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful