Check Character Type

Take a character and check whether it's uppercase, lowercase, a digit, or a special character.

Logic BuildingBeginner
Logic Building
# Take a character as input
ch = input("Enter a character: ")

# Check character type
if ch.isupper():
    print("Uppercase")
elif ch.islower():
    print("Lowercase")
elif ch.isdigit():
    print("Digit")
else:
    print("Special character")

Output

Enter a character: A
Uppercase

Enter a character: a
Lowercase

Enter a character: 5
Digit

Enter a character: @
Special character

Use string methods to check character type.

Key Concepts:

  • isupper(): checks if uppercase
  • islower(): checks if lowercase
  • isdigit(): checks if digit
  • Otherwise, it's a special character