Michael Mentele

software   learning-review

Book Review: Headfirst Python

The Head First books by Oreilly are fantastic introductory books to new topics. When learning something new I like to start with them and then move on from there into more ‘serious’ books.

For this post I’ll be reviewing my experience with Head First Python and how well it does at giving one an understanding of Python in genral.

What is Covers

It starts out with an overview of Python as an interpreted language and how the runtime might parse a simple module (python file) that has some import statements. It covers some syntax and basic programming ideas that I’ll gloss over here.

It moves on to fundamental data structures such as dicts (hashes), arrays, sets, tuples (immutable arrays) and primitives like strings. An interesting note is that strings are immutable in Python, this is contrary to languages like Ruby or Javascript.

There are a few features that really stuck out to me that other languages lack, namely a built-in help() function that reads docstrings for functions. This is so elegant!

Functions are first class entities with lexical scoping similar to Javascript functions in that functions can access external variable definitions.

After this overview of the basic core features of Python they jump straight into building a webapp with Flask. This was a bit of a departure from my experience with Headfirst Javascript. I skipped this section–I’m using Django and I’m really interested in the language at large. In this section they also introduce SQL and pickling which would be interesting for newbies.

Finally, they begin to talk about OOP in Python and jump into classes. One cool thing about here is they introduce a context manager. An automatic way of doing setup and teardown using the interface of the magic methods enter and exit defined on the object.

We then learn how to create our own decorators (functions that consume other functions) and have their own special syntax.

I was surprised that they bring up threading in this introductory book. It isn’t too much of a deep dive into threading itself and mostly covers optimizing utilization through concurrency.

Then we jump into generators and comprehensions which are so elegant.

Bottom Line

I would say that Head First into Python does a lot more than I expected. I thought it would give me more information on Python and how to be ‘Pythonic’ and really focus on OOP. Instead it provided a lot of context and was far more practical with a focus on webapps and DBs. I think it was a good book but if you are an experienced programmer you will be skipping large swathes of this book.

The most interesting sections to me were context management, decorators (which really aren’t all that special), comprehensions, generators, and getting used to the functional style of Python (ie. len() instead of list.length())