0%

🪄 The Spell That Unmasks Letters

With ord(), text becomes numbers. It returns the Unicode code point of any single character you give. Every character hides a secret key, and ord() is how you reveal it.
🔮 ord(“A”)

Behind every letter, there is a number. Hidden beneath the shape of A is a secret code. Not visible to the eye, but always present. The computer sees this number, not the letter. The ord() function pulls back the curtain. It takes a single character and returns its Unicode code point, the integer that represents that character in the universal character map.

🕯️ Magic Note

Unicode assigns a unique integer to every character across all human languages. ord() reveals this integer. Its counterpart, chr(), does the reverse. It takes an integer and returns the corresponding character. Together, they form a bridge between text and numbers.

The syntax ord(“A”) returns 65, because in Unicode (and ASCII), A is represented by the number 65. For an emoji like “🙂”, ord(“🙂”) returns 128578. Every character, no matter how exotic, has its own unique number.
  • Works on any single character, including emojis and non-English scripts
  • Raises TypeError if given a string longer than one character
  • The reverse function is chr() turning numbers back into characters
  • Useful for encryption, sorting, or character manipulation
💡 Use ord() to compare characters without worrying about their actual symbol.
For example, checking if a character is uppercase by comparing its code point with ord(“A”) and ord(“Z”).
For lowercase, compare with ord(“a”) and ord(“z”). This works across different locales.
Characterord() Value
“A”65
“a”97
“0”48
” ” (space)32
“🙂”128578
“é”233
⚠️ ord() only accepts a single character. Passing a string with multiple characters like ord(“AB”) raises a TypeError.
For converting longer strings to code points, use a loop or map(ord, string). Also be aware that some emojis are actually made of multiple code points (like skin tone modifiers), and ord() only reads the first one.
Examples

Python

# Converting characters to their code points

char = “A”

code = ord(char)

print(f”The hidden number of {char} is {code}”)

# Output: The hidden number of A is 65

Python

# Checking if a character is uppercase

def is_uppercase(char):

return ord(“A”) <= ord(char) <= ord("Z")

print(is_uppercase(“M”))

# Output: True

print(is_uppercase(“z”))

# Output: False

Python

# Converting an entire string to code points

text = “ABC”

codes = [ord(c) for c in text]

print(codes)

# Output: [65, 66, 67]

# Reverse using chr()

original = “”.join(chr(code) for code in codes)

print(original)

# Output: ABC

Common Mistakes
  • Passing a multi-character string to ord(), causing a TypeError
  • Confusing ord() with chr(), trying to get a character from a number using the wrong function
  • Assuming ord() works with ASCII only, it supports the full Unicode range including emojis and non-English scripts

⚡ Whisper

Every letter wears a mask. Behind the shape is a number, silent and hidden. ord removes the mask and reveals the truth. The character becomes data. The symbol becomes a key.