Python Brain Teasers (PragProg)

Miki Tebeka @tebeka

This book contains 30 simple Python programs and will challenge your understanding of Python. The Python programming language is a simple one, but like all other languages it has its quirks. This book uses these quirks as a teaching opportunity. By understanding the gaps in your knowledge - you’ll become better at what you do. These teasers will help you avoid mistakes. Some of the teasers are from my own experience shipping bugs to production, and some from others doing the same. Teasers are fun! We geeks love puzzles and solving them. You can use these teasers to impress your co-workers.

At the beginning of each chapter I’ll show you a short Python program and will ask you to guess the output. The possible answers can be:

  • Syntax error
  • Exception
  • Hang
  • Some output (e.g. [1 2 3])

There’s a lot of research showing that people who make mistakes during the learning process learn better than people who don’t. If you use this approach at work when fixing bugs - you’ll find you enjoy bug hunting more and become a better developer after each bug you fix.

Many of these brain teasers are from quizzes I gave at conferences and meetups. I’ve found out that people highly enjoy them and they tend to liven the room.

Before moving on to the answer and the explanation, go ahead and guess the output. After guessing the output I encourage you to run the code and see the output yourself, only then proceed to read the solution and the explanation. I’ve been teaching programming for many years and found this course of action to be highly effective.

Don’t forget you can get 35% off with your Devtalk discount! Just use the coupon code “" at checkout :+1:


Recently bought it. Really nice teasers, I strongly recommended this book to every Python programmer I know. Also, my first purchase with “” promo :wink: