Tutorial Study Image

Python isalpha()

The isalpha() function in python helps to check whether all the characters of a string are alphabets or not. The function returns true if all the characters are alphabets (can be uppercase and lowercase) otherwise returns false.


string.isalpha() 
 

isalpha() Parameters:

The isalpha() doesn't take any parameters. This function does not allow any special chars( ()!#%&?) even spaces.

isalpha() Return Value

The isalpha() method also can identify the  Unicode alphabets of other international languages. If the specified string is empty, then isalpha() returns False. 

Input Return Value
if all are alphabet True
if at least one is not an alphabet False

Examples of isalpha() method in Python

Example 1: Working of isalpha() in Python


string = "python"
print(string.isalpha())

# contains whitespace
string = "Python programming"
print(string.isalpha())

# contains number
string = "123python"
print(string.isalpha())
 

Output:


True
False
False

Example 2: Working of isalpha() with condition checking


string = "Programming"

if string.isalpha() == True:
   print("All characters are alphabets")
else:
    print("All characters are not alphabets.")
 

Output:


All characters are alphabets