Python Program to Check Given Input is Alphabet, Number or Special Character

Python program to check whether the given input is alphabet, number or special character; Through this tutorial, i am going to show you how to check whether the given input is alphabet, number or special character in python.

Python Program to Check Given Input is Alphabet, Number or Special Character

  • Python program to check whether the given input is alphabet, number or special character
  • Python Program to check character is Alphabet, Digit or Special Character using isalpha, isdigit functions.
  • Python Program to check character is Alphabet, Digit or Special Character using ASCII.

Python a program to check whether the given input is alphabet, number or special character in python

Use the below steps and write a program to check whether the given input is alphabet, number or special character in python:

  • Take input any characters/number/special character from user.
  • Then, Use if statement checks whether the given input character is between a and z or A and Z. If TRUE, it is an alphabet.
  • If condition returns false, it enters into elif statement. Inside the Elif, we are checking whether a character is between 0 and 9. If True, it is a digit.
  • If elif condition returnsfalse, it is a or special character.
# Python Program to check whether the given input is alphabet, number or special character
ch = input("Please Enter Any Character : ")
if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')): 
    print("The Given Character ", ch, "is an Alphabet") 
elif(ch >= '0' and ch <= '9'):
    print("The Given Character ", ch, "is a Digit")
else:
    print("The Given Character ", ch, "is a Special Character")

Output

Test 1

Please Enter Any Character :  ?
The Given Character  ? is a Special Character

Test 2

Please Enter Any Character :  h
The Given Character  h is an Alphabet

Python Program to check character is Alphabet, Digit or Special Character using isalpha, isdigit functions

You can check character is Alphabet, Digit or Special Character using isalpha, isdigit functions by using the following python program:

# Python Program to check whether the given input is Alphabet, Digit or Special Character
ch = input("Please Enter Any Character : ")
if(ch.isdigit()):
    print("The Given Character ", ch, "is a Digit")
elif(ch.isalpha()):
    print("The Given Character ", ch, "is an Alphabet")
else:
    print("The Given Character ", ch, "is a Special Character")

Output

Test 1

Please Enter Any Character :  5
The Given Character  5 is a Digit

Test 2

Please Enter Any Character :  D
The Given Character  D is an Alphabet

Test 3

Please Enter Any Character :  &
The Given Character  & is a Special Character

Python Program to check character is Alphabet, Digit or Special Character using ASCII.

Use the following step to check whether a given input value is alphabet, digit, or any special characters in python using if elif else statement with ASCII value:

  • Take input characters from user.
  • Then test condition using if elfi else statement in python with ASCII Value.
  • Print the result.
# Python Program to check whether the given input is Alphabet, Digit or Special Character using ascii
ch = input("Please Enter Any Character : ")
if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')): 
    print("The Given Character ", ch, "is an Alphabet") 
elif(ch >= '0' and ch <= '9'):
    print("The Given Character ", ch, "is a Digit")
else:
    print("The Given Character ", ch, "is a Special Character")

Output

Please Enter Any Character :  A
The Given Character  A is an Alphabet

Recommended Python Tutorials

Leave a Comment