Puzzle 3 When in Kraków

The Pragmatic Programmers
The Pragmatic Programmers
3 min readMar 23, 2022

--

Python Brain Teasers — by Miki Tebeka (12 / 40)

👈 A Slice of π | TOC | A Task to Do 👉

city.py

​ city = ​'Kraków'​
​ ​print​(len(city))

Guess the Output

IMPORTANT

Try to guess what the output is before moving to the next page.

images/hline.png

This code will print: 7

images/hline.png

Unicode

WARNING

If you’re reading this book in electronic format, don’t copy and paste the code from the book; you’ll probably get a different answer due to Unicode translation issues. Use the book source code. See the About the Code section on where to find it.

If you count the number of characters in Kraków, it’ll come out to 6. So why 7? The reason is … history.

In the beginning, computers were developed in English-speaking countries — the UK and the US. When early developers wanted to encode text in computers that only understand bits, they came out with the following scheme. Use a byte (8 bits) to represent a character. For example, a is 97…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.