Loading...
Character data encode symbols rather than their apparent numerical meanings. Distinguish a code point, its byte encoding and the glyph drawn on screen.
What you'll be able to do
The decimal integer 5 can be stored as binary 00000101 in an eight-bit unsigned format. The character "5" has a character code, 53 decimal in ASCII and the corresponding Unicode code point, whose eight-bit pattern is 00110101. The visible digit does not imply the same underlying value.
A sequence such as "25" contains two digit characters, while the integer twenty-five is a numerical value. Parsing text into a number interprets the character sequence; storing a number’s display characters is a separate representation choice.
Standard ASCII defines 128 codes, fitting seven bits, including letters, digits, punctuation and control characters. Its limited repertoire cannot represent the writing systems and symbols needed worldwide. Various historical extensions created compatibility problems rather than one universal extra set.
Unicode assigns code points across a much wider repertoire. It is not simply “ASCII with every character stored in sixteen bits”. Encodings such as UTF-8 and UTF-16 describe how code points are represented as units or bytes, with variable lengths for many characters.
UTF-8 preserves ASCII code points as single bytes but uses more bytes for many other characters. The number of visible symbols can differ from the number of code points when combining marks or joined sequences are involved. A font maps the interpreted text to displayed glyphs.
For examination calculations, use the character width and encoding assumptions stated in the question rather than assuming a universal byte count. In practical files, explicitly agree an encoding so that the same bytes are decoded consistently. A correct character code does not guarantee that every font contains the required glyph.
for text in ["5", "A", "é"]:
print(text, ord(text), list(text.encode("utf-8")))Scroll horizontally to see the full code or table.Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.
Common mistakes to avoid
Key takeaways
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.