0%

🪄 The Spell Of Pure Letters

Checks if a string contains only alphabetic letters. Spaces or numbers return False, while plain words return True.
🔮 “Programmer mode”.isalpha()

A string may look clean, but hidden inside could be numbers, spaces, or punctuation. You want to know if every single character is a letter and nothing else. No tricks. No exceptions. The isalpha() method is the purity test. It returns True only when the string is not empty and every character is an alphabetic letter from A to Z or a to z.

🕯️ Magic Note

This method ignores spaces, digits, punctuation, and any other non-letter characters. Even a single space in the string makes it return False. The check is Unicode aware, so it recognizes letters from non-English alphabets like é, ü, or ç as alphabetic characters.

The syntax “Programmer mode”.isalpha() scans the string character by character. The space between the words is not a letter, so the result is False. For a string like “PureMagic” with no spaces, the result is True.
  • Returns False for empty strings
  • Returns False if any character is not a letter
  • Recognizes Unicode letters, not just A to Z
  • Does not accept spaces, digits, or punctuation
💡 Use .isalpha() for validating names that should contain only letters. For checking if a string contains only letters and spaces, combine with .replace(” “, “”) or use .isalpha() after removing spaces. For checking letters and numbers together, use .isalnum() instead.
Input String.isalpha() Result
“Python”True
“Programmer mode”False
“Hello123”False
“Pure_Magic”False
“café”True
“”False
⚠️ .isalpha() returns False for empty strings, an edge case that can cause bugs if not handled. Also note that Unicode letters from other scripts like Cyrillic or Arabic are considered alphabetic. For strict English only checks, combine with .isascii() or use a regular expression.
Examples

Python

# Basic validation

name = “Feloriya”

if name.isalpha():

print(“Valid name, only letters”)

# Output: Valid name, only letters

Python

# Detecting unwanted characters

username = “user_123”

if not username.isalpha():

print(“Username contains non-letter characters”)

# Output: Username contains non-letter characters

Python

# Checking strings with spaces (returns False)

phrase = “hello world”

print(phrase.isalpha())

# Output: False

# Remove spaces first to check letters only

clean = phrase.replace(” “, “”)

print(clean.isalpha())

# Output: True

Common Mistakes
  • Forgetting that spaces are not letters, strings with spaces always return False
  • Assuming .isalpha() works on empty strings, it returns False not True
  • Using .isalpha() for usernames that may contain numbers or underscores, it will reject them all

⚡ Whisper

A string of pure letters speaks with a clear voice. No spaces. No numbers. No hidden marks. Only the alphabet. Only the essence. Test the purity before you trust the word.