Python - Get ASCII Value of a Character


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.

Example

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.

Python Program

ch = input('Enter a character : ')
ascii = ord(ch)
print('ASCII Value :', ascii)

Output #1

Enter a character : B
ASCII Value : 66

Output #2

Enter a character : m
ASCII Value : 109

Summary

In this Python Examples tutorial, we learned how to get the ASCII value of a character using ord() builtin function.