Check input character is alphabet or not by python by R4R Team

Every character in the computer have the unique ASCII value so alphabet also have their ASCII value.
like Uppercase alphabet A to Z have 65 to 90
and lowercase 'a' to 'z' have 97 to 122

Program -

print("Enter Any character")
a=input()

#first way
if 65<=ord(a)<=90 or 97<=ord(a)<=122:
print("Yes it is alphabet")
else:
print("No it is not alphabet")

#second way
if a.isalpha():
print("Yes it is alphabet")
else:
print("No it is not alphabet")


output-

Enter Any character
A
Yes it is alphabet
Yes it is alphabet

Enter Any character
r
Yes it is alphabet
Yes it is alphabet

Enter Any character
1
No it is not alphabet
No it is not alphabet

Enter Any character
@
No it is not alphabet
No it is not alphabet


- In this program ,we use two ways to find the character is alphabet or not
- In first way, we use ord() function which retrun the ascii value of any character so using using ASCII value we identify that character is alphabet or not.
- In second way, we use isalpha() function which is inbuild function in python, it check the character is alphabet or not.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!