Think(ing) Python

My review 🌟 of the book 📕 Think Python 🐍 by Allen Downey🧙🏽‍♂️

Think(ing) Python
Photo by Nick Morrison / Unsplash

The first semester of my learning journey covered topics of time management and personal knowledge management. On the second semester, I focus on building coding skills in Python, starting with the book Think Python by Allen B. Downey. In this post, I summarize my learnings from this publication.

Think Python, 3rd Edition
Python is an excellent way to get started in programming, and this clear, concise guide walks you through Python a step at a time—beginning with basic programming concepts before moving … - Selection from Think Python, 3rd Edition [Book]

I tried to learn how to code on two different occasions before I started this book. The first time was in college. I took an introductory class to programming in Delphi, where most of the time I was lost and barely scraped by. To put it into perspective, I had a much harder time with programming than I did with my Vector Calculus and PDE classes combined. I think the main problem was the level of abstraction. I feel there were assumptions made about the starting knowledge for the class that I didn’t meet.

My second foray with coding came a few of years ago, when I took the MOOC “Python for everybody” in Coursera by the great Dr. Chuck Severance. Even though he is an amazing teacher and I did learn a lot, my goals were fuzzy at best, so most of my knowledge vanished for lack of practice.

It is no surprise then that I had serious reservations and fears about my ability to understand much less complete Dr. Downey’s book. However, this time around I’m armed with a clear study plan and the conviction to master the skills needed to build software, so despite this gloomy preamble, I’m happy to report that the book proved to be the right fit for my learning needs.


📖 General overview

Think Python is an excellent choice to start learning how to code. The book is specifically written for people with no coding experience. The goal of the book is to cover the smallest set of the language that will provide the greatest capability with the fewest concepts (p. 5).

The author stresses that when we are learning to code, we are learning two languages (p. 4): the programming language itself and the vocabulary we will need to talk about programs, that is necessary to interpret error messages, read documentation, talk to another person, or use virtual assistants.

The first chapters are about Python Basic Elements, variables and statements. The author then introduces “the most important concept in programming”, functions (p. 4). Later chapters cover Python’s core data structures: lists, dictionaries and tuples. Files and databases are reviewed next. The last chapters are about Object-oriented programming (OOP), specifically classes and inheritance.

The author uses an incremental method to cover the material. Each chapter starts with a simple example, usually a few lines of code. These examples are then expanded and tweaked to solve more difficult problems. Ultimately, the procedures are progressively refined and made available for later use with encapsulation (converting a sequence of statements into a function definition) and generalization (replacing something unnecessarily specific - like a number - with a variable or parameter).

Each chapter has exercises at the end. They are usually extensions of examples already covered on the chapter and/or similar concepts that will use (in some capacity) the code shared on the chapter.

Another important aspect of the book is that the author includes a debugging section in each chapter. It was enlightening to learn that different kinds of programs might require a different debugging practice and that sometimes a simple print() instruction might shed light on the cause of the problem.

The book encourages the usage of AI chatbots to “accelerate the learning” (p. 6). The author includes a set of more in-depth questions at the end of each chapter as prompts to interact with the assistant and even suggests asking the chatbot for help with the most difficult problems.


📝 Procedure

While reading, I took notes using the Obsidian app. Following the author’s recommendation, I also created a Colab notebook for each chapter. I wrote each example and solved each exercise in a notebook.

I found it impossible to understand some of the functions/methods without first writing them and reviewing them line by line. I often changed a particular instruction to check the impact on the result of the procedure.  Fundamentally, working on the examples helped me dispel the illusion of competency.

I realized that for math and graphical examples, solving the problem first on paper and understanding what each set of instructions is doing first, eases writing the code. The “flower exercise” from chapter 4 (p. 88) drove this point home.

15 petals flower drawn in Chapter 4

To correctly draw the petals, it was essential to find the final position of the turtle before the turn. This showed me how important it is to not start writing the code blindly without a clear idea of what I needed to solve and/or create. In other words,  for problems like this, it is imperative to first understand what’s being asked, then work out a solution with pen and paper, and last start coding the solution.

The most challenging part of the book was working with inheritance for programmer-defined classes. The way we call the methods and the parameters we use are different from regular functions. It took me some time to get used to it. I frequently had to go back to the first parent class to review how the methods were defined. This worked for the exercises of card games (decks and hands) in chapter 17.

The last chapter of the book "Python Extras" showed me that by having a better understanding of the capabilities of Python, we can rewrite functions from previous exercises in an improved and optimized way. For instance, the use of sets (not covered in previous chapters) to determine if data is repeated can simplify the code. As the author stated:

Sometimes refactoring means that you have learned something (p. 79)

The use of AI was helpful for most of the problems, particularly when debugging and understanding specific issues with the code, although sometimes the suggestions were outside the scope of the material we were covering.

I also liked the fact that I could ask the assistant for more in-depth information about a method that wasn't quite clear from reading the original code. The assistant also provided me with helpful visual aids to get information fast about the main data structures and their differences:


Data Structures summary table created by ChatGPT

💡Final thoughts

I absolutely loved Think Python book. I couldn’t recommend it enough to any person beginning their coding journey. The structure of the book, starting with simple examples and progressively building complexity from them, makes it easier to grasp more difficult concepts.

Looking back at the code I wrote for the exercises, it is amazing to see how far I’ve come and although I know I still have a long way to go, this path doesn’t look as scary or bleak as it did before.

Subscribe to receive emails when new content is published