Get ASCII Value of a Character
To get ASCII value of a given character in Python, call the builtin function ord() and character as argument. ord() returns an integer value representing the ASCII value of given character.
In this example, we write a function to read a character (one character string) from user, and get the ASCII value of it using ord() function.
ch = input('Enter a character : ') ascii = ord(ch) print('ASCII Value :', ascii)
Enter a character : B ASCII Value : 66
Enter a character : m ASCII Value : 109
In this Python Examples tutorial, we learned how to get the ASCII value of a character using ord() builtin function.