Python String isalpha() Function
The String isalpha() method returns True if the string is not empty and all the characters are alphabetic. Otherwise, it returns False.
A character is alphabetic if it is either a letter [a-z] or [A-Z].
Syntax
my_string.isalpha()
isalpha() Parameters
Python String isalpha() function does not take any parameters.
isalpha() Return Value
Python String isalpha() function returns:
Trueif ALL characters in the string are alphabetic.Falseif AT LEAST ONE character is NOT alphabetic (numbers, symbols, etc.).
Examples
Example 1: Check if a String is alphabetic with isalpha()
The isalpha() method returns True if all characters are alphabetic.
For example, let's check if all characters in the string abcDEF are alphabetic:
my_str = 'abcDEF'
result = my_str.isalpha()
print(result) # Output: True
output
True
Example 2: Check if a String with Numbers is alphabetic with isalpha()
The isalpha() method returns False if at least one character is not alphabetic. Numbers [0-9] are NOT alphabetic characters!
my_str = 'abc123'
result = my_str.isalpha()
print(result) # Output: False
output
False
Example 3: Check if a String with Special Characters is alphabetic with isalpha()
The isalpha() method returns False if at least one character is not alphabetic. Special characters are NOT alphabetic characters!
my_str = 'abc@DEF'
result = my_str.isalpha()
print(result) # Output: False
output
False
Example 4: Check if an empty String is alphabetic with isalpha()
The isalpha() method returns False if the string is empty.
my_str = ''
result = my_str.isalpha()
print(result) # Output: False
output
False