Search⌘ K
AI Features

Puzzle 3: Explanation

Understand how Python string length can differ due to character encoding schemes like ASCII and UTF-8. Learn why some characters use multiple bytes and how Python manages Unicode to accurately process and count strings in coding puzzles.

We'll cover the following...

Let’s try it

Try executing the code below to verify the results:

Python 3.8
city = 'Kraków'
print(len(city))

Code explanation

If we count the number of characters in Kraków, it’ll come out to six. So, why is the correct answer 7? The reason—history! ...