Python Program to check character is Alphabet or not

Write a Python program to check character is Alphabet or not with a practical example.

Python Program to check character is Alphabet or not

This Python program allows a user to enter any character. Next, we use the If Else Statement to check whether the user given character is an alphabet or not. Here, the Python If else statement checks whether the character is between a and z or between A and Z. If it is TRUE, it is an alphabet; otherwise, it is not an alphabet.

ch = input("Please Enter Your Own Character : ")

if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
print("The Given Character ", ch, "is an Alphabet")
else:
print("The Given Character ", ch, "is Not an Alphabet")

Checking whether the character is an alphabet or not output.

Please Enter Your Own Character : q
The Given Character  q is an Alphabet
>>> 
Please Enter Your Own Character : 8
The Given Character  8 is Not an Alphabet

Python Program to verify character is Alphabet or not using ASCII Values

In this code, we use ASCII Values inside the If Else Statement to check whether the character is an alphabet or not. For more, Please refer to the Python tutorial page and the Python isalpha function.

ch = input("Please Enter Your Own Character : ")

if((ord(ch) >= 65 and ord(ch) <= 90) or (ord(ch) >= 97 and ord(ch) <= 122)):
print("The Given Character ", ch, "is an Alphabet")
else:
print("The Given Character ", ch, "is Not an Alphabet")
Please Enter Your Own Character : W
The Given Character  W is an Alphabet
>>> 
Please Enter Your Own Character : #
The Given Character  # is Not an Alphabet

Python Program to find character is Alphabet using isalpha functions

In this example code, we use the isalpha string function to check whether a given character is an alphabet or not. For more examples, refer to the Python Basic Programs.

ch = input("Please Enter Your Own Character : ")

if(ch.isalpha()):
print("The Given Character ", ch, "is an Alphabet")
else:
print("The Given Character ", ch, "is Not an Alphabet")
Program to check character is Alphabet or not 3

Also Read