Python - Check if a Character is Alphabet or Not


Check if a Character is Alphabet or Not

To check if given character is an alphabet or not in Python, call the string function isalpha(), and pass the character as argument. String.isalpha() returns a boolean value of True if the given character is an alphabet, or False otherwise.

Program

In this example, we write a function to read a character from user, and check if the character is alphabet or not.

Python Program

ch = input('Enter a character : ')
if ch.isalpha():
    print(ch, 'is an alphabet.')
else:
    print(ch, 'is not an alphabet.')

Output #1

Enter a character : b
b is an alphabet.

Output #2

Enter a character : 5
5 is not an alphabet.

Summary

In this Python Examples tutorial, we learned how to check if given character is an alphabet or not.