ord() and chr() in Python
ord("A") returns the number code of a character (65). chr(65) turns a number code back into its character ("A"). Ciphers use them to change letters to numbers and back.
Understanding ord() and chr() in Python in ACARA Digital Technologies Years 9–10
What it does: ord("D") is 68 and ord("A") is 65, so the result is 3, the position of D in the alphabet starting from 0. 2 + 65 is 67, and chr(67) is "C", so the position 2 becomes the letter C. ord() turns a character into its number code. The code for capital A is 65. Think of ord as 'order number' of a character. chr goes the other way, from number to character. chr() takes a number and gives a character. ord() needs a character, so ord(72) causes an error. A is 65, so subtracting 65 makes A = 0, B = 1 and D = 3.
Common mistakes: chr() turns a number into a character, so it cannot take the letter "A". To get the number code of a letter, use ord(letter). ord() only accepts a single character. Passing the whole string "HI" causes a TypeError. It should be ord(first), which is the single letter "H".
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 860–875) and word search (Modules 860–944).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
ord() and chr()Fill in the Blanks
Spot the Error
Student with a class code? Join your class →