What is String.isalpha in Python?

The isalpha method will return True if all the characters of the string are alphabetic; otherwise, it returns False. If the string is empty, then the isalpha method will return False.

isalpha will return True if all the characters of the string are defined in the LetterLetter (L): lowercase (Ll), titlecase (Lt), uppercase (Lu), modifier (Lm), other (Lo) Category of the Unicode character Database. Refer here for Unicode Character categories.

Syntax

string.isalpha()

Return value

  • True: If all the characters of the string are alphabetic.

  • False: If any one of the characters of the string is not alphabetic or if the string is an empty string.

Example

string = "text"
print(string.isalpha())
#isalpha returns false because string has numbers
string = "ab3"
print(string.isalpha())
#isalpha returns false because the string has spaces
string = "I have space"
print(string.isalpha())
#for empty string isalpha returns false
string = ""
print(string.isalpha());

In the code above:

  • We call isalpha on the text string. The isalpha will return True because all the characters of the string are alphabetic.

  • We call isalpha on the ab3 string. The isalpha will return False because the string contains a numerical character.

  • We call isalpha on the I have space string. The isalpha will return False because the string contains a space character.

  • We call isalpha on the empty string. For the empty string, the isalpha method will return False.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources