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!

Zack West
CodeX

--

Image by: alpharithms

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.

--

--

Zack West
CodeX
Writer for

Entrepreneur, programmer, designer, and lifelong learner. Can be found taking notes from Mother Nature when not hammering away at the keyboard.