🕯️ 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.
- 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
| Input String | .isalpha() Result |
|---|---|
| “Python” | True |
| “Programmer mode” | False |
| “Hello123” | False |
| “Pure_Magic” | False |
| “café” | True |
| “” | False |
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
- 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.