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 If Else Statement to check whether the user given character is an alphabet or not. Here, If statement checks 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.

# Python Program to check character is Alphabet or not
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")

Python character is 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 Python code, we use ASCII Values inside the If Else Statement to check the character is an alphabet or not.

# Python Program to check character is Alphabet or not
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 python code, we use isalpha string function to check whether a given character is an alphabet or not.

# Python Program to check character is Alphabet or not
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")
Python Program to check character is Alphabet or not 3