Puzzle 3 When in Kraków
Python Brain Teasers — by Miki Tebeka (12 / 40)
👈 A Slice of π | TOC | A Task to Do 👉
city = 'Kraków'
print(len(city))
Guess the Output
IMPORTANT
Try to guess what the output is before moving to the next page.
This code will print: 7
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…