Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 3.4 — Unicode, Bytes and Encodings
Python · Example 3 of 3

Normalisation and lookalike characters

A Python str is a sequence of Unicode code points (numbers that stand for characters), while bytes is a sequence of raw numbers from 0 to 255. Turning text into bytes is encoding and the reverse is decoding; almost every mysterious bug with accents, emoji or é garbage is an encoding mismatch.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Print how many characters and how many UTF-8 bytes are in the text "Hectal ₹".

02

Make mojibake by decoding the UTF-8 bytes of "café" as Latin-1, print it, then repair it.

03

Print the letter that is 3 places after "a" using ord and chr, and the letter 25 places before "z".

Explain it without notes

01

What is the difference between a character, a code point and a byte?

02

Why can len(text) differ from len(text.encode("utf-8"))?

03

What causes UnicodeDecodeError, and what does é in text tell you?

04

Why can two strings that print the same be unequal, and how do you fix it?

Normalisation and lookalike characters
Sign in to run this example in your browser.

Expected output

é é 1 2 False
1 1 True
LATIN SMALL LETTER E WITH ACUTE | COMBINING ACUTE ACCENT
2 5 1
STRASSE strasse