Python Program to Find ASCII Value of Character

ASCII stands for American Standard Code for Information Interchange.

It is a numeric value given to different characters and symbols, for computers to store and manipulate. For example, the ASCII value of the letter 'A' is 65.


Python code using ord function : 

ord(): It converts the given string of length one, returns an integer representing the Unicode code point of the character. For example, ord(‘a’) returns the integer

code:-

print(ord('b'))
print(ord('A'))
print(ord('2'))
print(ord('$'))
output:-

98
65
50
36
>>> 

example 1:

K = input("Please enter a character: ")    
    
print ("The ASCII value of '" + K + "' is ", ord(K))  

output:-

Please enter a character: s
The ASCII value of 's' is  115

example 2:


print ("Please enter the String: ", end = "")  
string = input()  
string_length = len(string)  
for K in string:  
    ASCII = ord(K)  
    print (K, "\t", ASCII)  
output:-
Please enter the String: vikram
v 	 118
i 	 105
k 	 107
r 	 114
a 	 97
m 	 109

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post