The str.isalpha() method returns True if all characters in the string are alphabetic letters and the string contains at least one character. It returns False if the string contains digits, whitespace, punctuation, symbols, or is empty.
Unicode Letter Classification: isalpha() checks against Unicode General Categories L* (including uppercase Lu, lowercase Ll, titlecase Lt, modifier Lm, and other letter Lo). It recognizes international alphabets globally (such as Cyrillic, Greek, Hebrew, Arabic, and CJK ideographs).
The isalpha() method is a built-in string method requiring zero arguments:
is_pure_letters = string.isalpha()
| Parameter | Type | Description |
|---|---|---|
| None | — | The method takes no arguments. Passing arguments raises TypeError. |
| Return Value | bool |
Returns True if all characters are alphabetic letters and length > 0; otherwise False. |
Any character that is not strictly an alphabetic letter causes the method to evaluate to False:
# Pure letter strings evaluate to True
print("Python".isalpha()) # True
print("Welcome".isalpha()) # True
print("ABCxyz".isalpha()) # True
# Digits, whitespace, and punctuation evaluate to False
print("plus2net".isalpha()) # False: contains digit '2'
print("Hello World".isalpha()) # False: contains space ' '
print("user_name".isalpha()) # False: contains underscore '_'
print("Hello!".isalpha()) # False: contains exclamation mark '!'
print("12345".isalpha()) # False: pure digits
print("".isalpha()) # False: empty string always returns False
Output:
True
True
True
False
False
False
False
False
False
" ") or an empty string ("") returns False. If validating multi-word text like full names or sentences, checking string.isalpha() directly will fail unless spaces are stripped or handled separately.
Python 3 treats all world alphabets as valid letters under Unicode General Categories Lu, Ll, Lt, Lm, and Lo:
# European accented letters
print("Café".isalpha()) # True (é is category Ll)
print("München".isalpha()) # True (ü is category Ll)
print("España".isalpha()) # True (ñ is category Ll)
# Cyrillic, Greek, and Asian scripts
print("Москва".isalpha()) # True (Cyrillic letters)
print("Αθήνα".isalpha()) # True (Greek letters)
print("日本語".isalpha()) # True (Japanese Kanji / category Lo)
print("한국어".isalpha()) # True (Korean Hangul)
# Roman numerals are classified as Number Letter (Nl), NOT pure letters
print("Ⅳ".isalpha()) # False: Unicode Roman numeral 4 is category Nl
Output:
True
True
True
True
True
True
True
False
The table below summarizes how common string inspection methods differ when evaluating letters, digits, underscores, and international text:
| Sample String | isalpha() |
isalnum() |
isascii() |
isidentifier() |
|---|---|---|---|---|
"Hello" | True | True | True | True |
"Hello2" | False | True | True | True |
"2026" | False | True | True | False (starts with digit) |
"my_var" | False (has _) | False | True | True |
"Café" | True | True | False (non-ASCII é) | True |
"Hello World" | False (space) | False | True | False |
"" (empty) | False | False | True | False |
In web forms and onboarding workflows, testing human names with raw name.isalpha() causes false rejections for legitimate names such as Mary Jane, Anne-Marie, or O'Connor. Here is how production systems handle permitted punctuation:
def is_valid_person_name(name):
name = name.strip()
if not name:
return False
# Strip standard allowed name delimiters: spaces, hyphens, and apostrophes
clean_letters = name.replace(" ", "").replace("-", "").replace("'", "")
return clean_letters.isalpha()
print("John:", is_valid_person_name("John")) # True
print("Mary Jane:", is_valid_person_name("Mary Jane")) # True
print("O'Connor:", is_valid_person_name("O'Connor")) # True
print("Jean-Luc:", is_valid_person_name("Jean-Luc")) # True
print("User123:", is_valid_person_name("User123")) # False (digits)
print("Admin_01:", is_valid_person_name("Admin_01")) # False
Output:
John: True
Mary Jane: True
O'Connor: True
Jean-Luc: True
User123: False
Admin_01: False
When preprocessing natural language corpora, filtering tokens with token.isalpha() discards numbers, symbols, and punctuation noise, preserving pure vocabulary words:
sentence = "In 2026, Python 3.14 delivers 25% faster asynchronous execution!"
raw_tokens = sentence.split()
# Extract purely alphabetic words (stripping trailing punctuation)
pure_words = [w.strip(".,!?:;") for w in raw_tokens if w.strip(".,!?:;").isalpha()]
print("Filtered vocabulary words:")
print(pure_words)
Output:
Filtered vocabulary words:
['In', 'Python', 'delivers', 'faster', 'asynchronous', 'execution']
International standards like ISO 3166-1 define two-letter (Alpha-2, e.g. "US", "IN") and three-letter (Alpha-3, e.g. "USA", "IND") country codes:
def is_valid_iso_alpha_code(code, expected_length=2):
code = code.strip()
return len(code) == expected_length and code.isalpha() and code.isupper()
print("US valid Alpha-2:", is_valid_iso_alpha_code("US", 2)) # True
print("IND valid Alpha-3:", is_valid_iso_alpha_code("IND", 3)) # True
print("U1 invalid:", is_valid_iso_alpha_code("U1", 2)) # False
Output:
US valid Alpha-2: True
IND valid Alpha-3: True
U1 invalid: False
The following production script implements an enterprise name parser and a lexical token analyzer with automated self-checking unit assertions:
class LexicalValidator:
def __init__(self, min_name_len=2, max_name_len=50):
self.min_name_len = min_name_len
self.max_name_len = max_name_len
def validate_human_name(self, full_name):
# Validates multi-part personal names supporting spaces, hyphens, and apostrophes
if not isinstance(full_name, str):
return False
trimmed = full_name.strip()
if not (self.min_name_len <= len(trimmed) <= self.max_name_len):
return False
# Verify that all characters are letters or allowed delimiters
letters_only = trimmed.replace(" ", "").replace("-", "").replace("'", "")
return len(letters_only) > 0 and letters_only.isalpha()
def classify_token(self, token):
# Classifies a string token into its structural category
if not token:
return "EMPTY"
if token.isalpha():
return "WORD"
if token.isdigit():
return "NUMBER"
if token.isalnum():
return "ALPHANUMERIC_CODE"
return "MIXED_OR_PUNCTUATION"
# --- Unit Assertions and Verification ---
validator = LexicalValidator()
# 1. Standard and international human name validation
assert validator.validate_human_name("Alexander") is True
assert validator.validate_human_name("Jean-Claude") is True
assert validator.validate_human_name("Mary Jane O'Connor") is True
assert validator.validate_human_name("Renée") is True
assert validator.validate_human_name("User_123") is False
assert validator.validate_human_name("John Doe 2nd") is False
assert validator.validate_human_name("") is False
# 2. Token classification checks
assert validator.classify_token("Algorithm") == "WORD"
assert validator.classify_token("2026") == "NUMBER"
assert validator.classify_token("Python3") == "ALPHANUMERIC_CODE"
assert validator.classify_token("hello_world") == "MIXED_OR_PUNCTUATION"
assert validator.classify_token("") == "EMPTY"
print("Name 'Mary Jane O\'Connor' valid:", validator.validate_human_name("Mary Jane O'Connor"))
print("Token 'Algorithm' category: ", validator.classify_token("Algorithm"))
print("All str.isalpha() unit assertions passed successfully!")
Open in Google Colab View on GitHub
Run all alphabetic string inspections interactively, test international writing systems, benchmark token classifiers, and validate multi-part names in Google Colab.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.