Home » How to Check if a Character is Alphabet in Python

How to Check if a Character is Alphabet in Python

Learn about How to Check if a Character is Alphabet in Python in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

Contents

How to Check if a Character is Alphabet in Python

You can check the characters using their ASCII value. The ASCII values of the alphabet lie between 65 to 90 and 97 to 122. If the given character lies in between these ranges then we can say that it is an Alphabet.

Program:

# Python program to check whether a character is alphabet or not

# character input
ch = input("Enter any character: ")

# check charater is alphabet or not
if((ord(ch) >= 65 and ord(ch) <= 90) or (ord(ch) >= 97 and ord(ch) <= 122)):
    print(ch, "is an Alphabet.")
else:
    print(ch, "is not an Alphabet.")

Output:

Enter any character: d
d is an Alphabet.

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : isalpha() Method in Python