Command Palette

Search for a command to run...

Hectal
Phase 3: Strings and Text in Depth
Python · Exercise 5 of 6 PreviousNext
Beginner

Characters against bytes

word holds "naïve ₹". Make four variables: data is the UTF-8 bytes of word; char_count is the number of characters in word; byte_count is the number of bytes in data; restored is data decoded back to a string.

Then print 7 characters, 10 bytes using your variables in an f-string.

What Check tests

  1. data is a bytes object with the UTF-8 encoding
  2. char_count is 7
  3. byte_count is 10
  4. restored equals the original word
  5. The counts come from len, and data really is decoded back
  6. The program prints 7 characters, 10 bytes

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.