Determines whether the string contains alphabetic characters
Usage
The isalpha()
method returns TRUE if the string is nonempty and all characters in it are alphabetic (a-z or A-Z). Otherwise, it returns FALSE.
Syntax
string.isalpha()
Basic Example
# Check if all characters in the string are alphabetic
S = 'abc'
x = S.isalpha()
print(x)
# Prints True
String with Number/Special Character
The isalpha()
method returns FALSE if at least one character is not alphabetic.
S = '123'
x = S.isalpha()
print(x)
# Prints False
S = 'abc123'
x = S.isalpha()
print(x)
# Prints False
# even a space
S = 'abc xyz'
x = S.isalpha()
print(x)
# Prints False
isalpha() on Empty String
The isalpha()
method returns FALSE if the string is empty.
S = ''
x = S.isalpha()
print(x)
# Prints False