In this Python Program, we will learn how to check whether the entered character is an alphabet or not. We will use three ways to check whether the entered character is an alphabet or not.
Here is the source code of the program to check whether the entered character is an alphabet or not.
Python Program to Check Whether the Entered Character is an Alphabet or Not
# Python Program to Check Whether the Entered Character is an Alphabet or Not
# To take input from user
ch = input("Enter a character: ")
if((ch>='a' and ch<= 'z') or (ch>='A' and ch<='Z')):
print(ch, "is an Alphabet")
else:
print(ch, "is not an Alphabet")
Enter a character: 5
5 is not an Alphabet
Enter a character: #
# is not an Alphabet
Enter a character: W
W is an Alphabet
In this program, we used the isalpha()
function to check Check Whether the Entered Character is an Alphabet or Not.
Python Program to Check Whether the Entered Character is an Alphabet or Not - Using isalpha() function
# Python Program to Check Whether the Entered Character is an Alphabet or Not - Using isalpha() function
# To take input from user
ch = input("Enter a character: ")
if(ch.isalpha()):
print(ch, "is an Alphabet")
else:
print(ch, "is not an Alphabet")
Enter a character: d
d is an Alphabet
Enter a character: 5
5 is not an Alphabet
Enter a character: $
$ is not an Alphabet
Program 3: Python Program to Check Whether the Entered Character is an Alphabet or Not - Using ASCII Values
# Python Program to Check Whether the Entered Character is an Alphabet or Not - Using ASCII Values
# To take input from user
ch = input("Enter a character: ")
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")
Enter a character: 5
5 is not an Alphabet
Enter a character: F
F is an Alphabet
Enter a character: *
* is not an Alphabet
Comments