isalpha in Python: String Letter Check

When you check whether a text value contains only letters, you need a clear rule for every character in it. Python’s isalpha() method returns True when a nonempty string consists entirely of Unicode letters.

This article shows how to call isalpha() and how empty strings or combining marks affect its result.

TL;DR: Check Letters with isalpha()

Call isalpha() on the string to check that it contains at least one character and every character is a Unicode letter.

  • Spaces, digits and punctuation make the result False.
  • An empty string also returns False.
  • Accented and non-Latin letters can return True, while combining marks may return False.

What Is isalpha() in Python?

str.isalpha() is a built-in string method that answers whether a nonempty string consists entirely of alphabetic characters. Its result is the Boolean value True or False, so you can use it in an if condition or store it for a later validation decision.

Python’s definition follows Unicode general categories Lm, Lt, Lu, Ll and Lo, which include several letter forms. English A-to-Z is only part of this range. In my run, “café” and Japanese letters passed.

A space, hyphen, apostrophe or digit makes the full string fail. Use Python’s isalnum() method when numbers should pass too.

The method belongs to str, Python’s text type. It returns a Boolean and leaves the original value unchanged. I checked ordinary and accented samples in my run.

How to Use isalpha() Step by Step

Call the method directly on a string value, then use its Boolean result for the rule you want to enforce. The following run checks ordinary input, Unicode text and related character categories.

Step 1: Call the method on a string

Put parentheses after isalpha() and call it on the value being checked. Save this example in isalpha_demo.py, then run it with the command below.

samples = ["Python", "Python 3", "", "café", "Cafe\u0301", "東京", "²"]
for value in samples:
    print(f"{ascii(value)}: {value.isalpha()}")

superscript_two = "²"
print(f"str.isalpha(): {superscript_two.isalpha()}")
print(f"str.isdigit(): {superscript_two.isdigit()}")
print(f"str.isnumeric(): {superscript_two.isnumeric()}")

try:
    value = None
    value.isalpha()
except AttributeError as error:
    print(f"None input: {type(error).__name__}: {error}")

Run the file from the folder where you saved it:

python3 isalpha_demo.py

The command prints the result for each sample. I ran it and got this output:

'Python': True
'Python 3': False
'': False
'caf\xe9': True
'Cafe\u0301': False
'\u6771\u4eac': True
'\xb2': False
str.isalpha(): False
str.isdigit(): True
str.isnumeric(): True
None input: AttributeError: 'NoneType' object has no attribute 'isalpha'
Terminal output from running isalpha_demo.py with string classification examples
Running isalpha_demo.py and checking its printed results

The command checks plain text, a space, an empty value and Unicode text. Use its Boolean result in a condition such as if value.isalpha(): when the input rule is “letters only.”

Step 2: Choose the character rule you mean

For English ASCII letters only, combine isascii() and isalpha() so a Unicode letter such as é does not pass the narrower rule. isascii() alone also accepts an empty string, so the second check still matters when input must contain a letter.

The run checks superscript two, which returns False for isalpha(). Both isdigit() and isnumeric() return True for it. These methods classify text rather than converting it to a number.

For an input rule that permits spaces between words, check the pieces rather than removing every separator without thought. The allowed punctuation is a product decision. A name, a language identifier and a search token can each need a different rule.

Choose the method by the characters your input rule allows. isalnum() accepts a nonempty string of letters and numeric characters, while isalpha() rejects every digit. isdigit() and isnumeric() classify numeric characters, and their Unicode definitions include characters beyond the ASCII digits 0 through 9.

For example, a superscript numeral can pass isdigit() while failing isalpha(). This distinction matters when validating identifiers or labels. If a format requires ordinary decimal digits, define that rule directly rather than treating every numeric-looking Unicode character as interchangeable.

Edge Cases: Empty, Unicode and Non-String Values

Check the exact kind of text your program receives, because empty values, Unicode normalization and non-string objects change the result or raise an error.

An empty string returns False, as does a string made only of spaces. That helps reject missing text, but not whether input remains after trimming. For surrounding whitespace, follow AskPython’s guide to removing spaces from a string and call strip() when appropriate.

value = "   "
print(value.isalpha())
print(value.strip().isalpha())

Unicode text can look identical while using different sequences of code points. In my run, the precomposed form “café” returned True. “Cafe” followed by a combining acute accent returned False because the accent mark is outside the Letter categories used by isalpha().

Normalize input with unicodedata.normalize() using the form chosen for your application when equivalent spellings should match. Normalization changes representation but does not define the allowed alphabet. Use isascii() too for ASCII-only text.

A non-string value has no string method. Passing None raised AttributeError: ‘NoneType’ object has no attribute ‘isalpha’. Check the type before calling string methods.

value = None
if isinstance(value, str):
    print(value.isalpha())
else:
    print("Expected text")

These checks classify characters, not complete language rules. A string of letters may still violate an account name’s length or reserved-word rules. Add such requirements as separate checks.

Conclusion

Case does not affect isalpha(). Uppercase and lowercase letters both qualify, and the method does not translate between them. If a later comparison should ignore case, use a separate case-normalization decision rather than changing the classification rule.

For a single character, apply the same check to that one-character string. For a larger value, remember that isalpha() requires every character to pass. When the goal is to find whether text contains at least one letter, inspect the characters for that condition instead of using the whole-string result as a proxy.

That distinction is useful for search filters and reports. A line may include words and punctuation yet still contain letters. A validation rule for a code, by contrast, may reject that same line because every character must fit its allowed set.

Python 3 str values hold Unicode text, but bytes are sequences of byte values. The bytes.isalpha() method follows ASCII letters only, so decode file or network data to text before applying Unicode character rules. Choose an explicit encoding at the input boundary so classification runs on characters rather than encoded bytes.

Also decide whether the whole value must contain only letters or whether it needs to contain at least one letter. isalpha() checks the whole nonempty value, so digits or punctuation anywhere make it False. A search for any letter is a different test and should inspect characters one by one.

Unicode normalization can make canonically equivalent text use a consistent representation before classification. It does not remove spaces or punctuation. Keep normalization separate from the acceptance rule so the program can explain why an input passed or failed.

Use str.isalpha() when a nonempty string must contain only Unicode letters. Test empty values and combining marks against the input you expect, then choose an ASCII or alphanumeric check only when the requirement calls for it.

For the exact character definitions, see Python’s string method documentation. The unicodedata documentation describes normalization forms used when text representation matters.

FAQ

These answers cover common questions about what the method accepts.

Does isalpha() allow spaces?

No. A space is not a Unicode letter, so a string containing a space returns False.

Does isalpha() accept accented letters?

Yes, when each character belongs to one of Python’s documented Unicode Letter categories. A decomposed combining mark can cause the result to be False.

How do I check for ASCII letters only?

Use value.isascii() and value.isalpha() so the string is both ASCII and alphabetic.

What does isalpha() return for an empty string?

It returns False because the method requires at least one character.

Pankaj Kumar
Pankaj Kumar

I have been working on Python programming for more than 12 years. At AskPython, I share my learning on Python with other fellow developers.

Articles: 261