The String isalpha() method returns True if the string is not empty and all the characters are alphabetic. Otherwise, it returns False.
Syntax
my_string.isalpha()isalpha() Parameters
Python String isalpha() method does not take any parameters.
isalpha() Return Value
Python String isalpha() method 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: Trueoutput
TrueExample 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: Falseoutput
FalseExample 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: Falseoutput
FalseExample 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: Falseoutput
False