Definition
The mechanism by which Python maps human-readable symbols (characters) to numeric values (code points) understood by hardware.
Why It Matters
Unicode is the ‘Universal Translator’ of the digital age. It ensures that every character from every language can be represented consistently on any computer, providing the foundational infrastructure for global communication and software localization.
Core Concepts
ord(char): Returns the integer Unicode code point for a single character (e.g.,ord('A')is65).chr(int): Returns the string character for a given Unicode code point (e.g.,chr(65)is'A').- Comparison Logic: Python compares strings based on these numeric values (e.g.,
'A' < 'a'isTruebecause65 < 97). - Unicode: A universal standard that covers nearly every written language and symbol (emoji, etc.), ensuring consistent display across platforms.
# Character to numeric code point
print(ord('A')) # Output: 65
# Code point to character
print(chr(65)) # Output: 'A'
# Emoji support
print(ord('🐍')) # Output: 128013