Python Ord: Getting the Ordinal Value of a Unicode Character
Ordinal values are fun ways to find the numerical representation of characters. These numbers can help translate text between machines, encode data across networks, and maybe even create your own secret language! Python’s built-in ord() function makes converting between numbers and characters a breeze!
Python provides a host of built-in utilities for translating between encoded and numerical representations of values, strings, and everything in between. The Python ord function is a built-in utility that, given a single Unicode character, will return its ordinal value.
The term ordinal means countable and in the context of Python’s ord
function will return the integer value assigned to a character in the Unicode encoding system. This can be useful when converting between bytes to strings, binary to encoded representations, or sheer hobbyism.
In this article, I will showcase the basics of what the ord function does in Python, why you should care, and some quirky edge cases, and the history behind them.