Python program to check the given character is alphabet or digit or special character

Hello everyone, welcome to nkcoderz.com. In this article we will going to discuss about Python program to check the given character is alphabet or digit or special character.

Here’s a Python program that will check whether a given character is an alphabet, a digit, or a special character:

Code for python program to check the given character is alphabet or digit or special character

def check_char(c):
  if c.isalpha():
    print(f"{c} is an alphabet.")
  elif c.isdigit():
    print(f"{c} is a digit.")
  else:
    print(f"{c} is a special character.")

# Test the function
check_char('a')
check_char('1')
check_char('$')

Output

a is an alphabet.

1 is a digit.

$ is a special character.

Explanation

This program uses the isalpha() and isdigit() methods to check whether a character is an alphabet or a digit, respectively. If the character is neither an alphabet nor a digit, it is assumed to be a special character.

You can test this program by calling the check_char function with any character as the argument. The function will print out whether the character is an alphabet, a digit, or a special character.

Python program to check the given character is alphabet or digit or special character

Conclusion

If you liked this post, then please share this with your friends and make sure to bookmark this website for more awesome content.


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment