ord And chr Map Code Points
ord returns the code point behind a character and chr inverts it, so char-level text math works on Unicode strings that iterate one code point at a time.
Code
print("ord('A'):", ord("A"))
print("chr(9731):", chr(9731))
print("roundtrip:", chr(ord("A")) == "A")
# one code point per character: strings iterate by code point
text = "ab☃"
print("chars:", [ch for ch in text])
print("code points:", [ord(ch) for ch in text])
# both the \u and \N{} escapes produce the same character
print("escapes:", "\u2603", "\N{SNOWMAN}", "\u2603" == "\N{SNOWMAN}")Output
Captured from a sandboxed run of this snippet in the build pipeline.
ord('A'): 65
chr(9731): ☃
roundtrip: True
chars: ['a', 'b', '☃']
code points: [97, 98, 9731]
escapes: ☃ ☃ TrueHow it works
Demo state sits in top-level bindings: text.
Caveats
- Self-contained — imports go no further than what the runtime provides.
Applying it to real inputs
Look for the ord(, chr(9731):, roundtrip: prefixes once the file starts running; each one ties a printed line to the step that produced it.
Interactive Tools for This Topic
ASCII Table ReferenceLook up any ASCII code point 0-127 by decimal, hex, or character and see the binary, octal, and control-name view.Character Frequency AnalyzerCount how often each character appears in a text, with Unicode code points, optional case folding, and whitespace exclusion.Git Conventional Commit BuilderBuild and validate Conventional Commits v1.0.0 messages with type, scope, breaking markers, 72-char subject counter, body, footers, and git CLI command.Glob Pattern TesterCompile glob patterns with *, **, ?, character classes, and braces into regex and test them against a list of candidate file paths.
FAQ
- Is the dependency story complicated?
- Not at all: zero dependencies, so there is nothing to version or audit. Its state lives in module-level bindings: `text`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.