I’ve been programming in Python for a few years now (I can pretty much mark the beginning because of starting at Red Hat). Since picking it up, I’ve fallen in love with the language and have a few books on the subject. One of the most indispensable books I have is Learning Python 3rd Edition published by O’Reilly. Recently I received a copy of the 5th Edition for review.
My first reaction was that it was no mere book, but a tome. The 3rd Edition was no slouch, weighing in at 700 pages, but the 5th Edition is a hefty 1540 pages, over twice the size! This edition was released in June 2013 (ISBN 978-1-449-35573-9); the previous edition that I owned (the 3rd) was published in October 2007. This new edition was updated to cover Python versions 3.3 and 2.7 (the 4th Edition covered 2.6 and 3.0/3.1, so I imagine it too had a hefty size increase over the 3rd Edition).
Before I go further with the review I have to note that Learning Python 3rd Edition is nearly always on my desk. I referenced that book all the time. With the number of alternatives out there (searching on the internet or looking at other books that I have, such as Programming Python, the Python Cookbook, and Python in a Nutshell), this is the one book I used all the time. It is worn, crinkled, dirty, and probably sticky in a few spots as well. However, I’m not one to read books like this from front to back — I use them as reference material for areas that interest me or I need help with (or I need to brush up on).
The first section of the book, “Getting Started” goes into the basics of Python: what it is, what it’s used for, how to use it, why you would use it, and so forth. The 5th Edition expands on this, particular in regards to version 3.3 and its new options in Windows. This is all the really basic stuff, explained quite well and great for those interested in getting into Python without a lot of knowledge of the language. Those more experienced with Python will likely skip this section for the most part, but there are some good bits in here.
The second section of the book, “Types and Operations”, gets to the meat of writing code. This is the section that talks about Python object types (lists, dictionaries, tuples), how Python handles numbers, dynamic typing, manipulating and using strings, and handling file operations. One thing I noticed immediately is that the section dealing with numbers is greatly expanded from the 3rd Edition and this is largely due to the changes of how these are handled in Python 2.x vs 3.x. It is in this chapter that you begin to see why the book is so hefty — instead of focusing on just one major version of the language, it provides the necessary information for both 2.x and 3.x and the differences between the two. Because Python 2.x is still so widely used, it would have been impossible to ignore it unless they decided to write two books, one for each major version. The section on handling strings has likewise been expanded, enhanced, and re-organized with quite a bit of extra content. Again, quite a bit of this is due to the coverage of both Python 2.x and 3.x.
The third section of the book, “Statements and Syntax”, gets into the fundamentals of handling your code: typical statements (if/elif/else, variable assignments, loop handling, creating functions, namespaces, module handling, and exception handling). Here again a lot of content is devoted to the differences between 2.x and 3.x, and even between different versions of 2.x. There is a lot of content here — chapters devoted to topics about looping, if statements, iteration and comprehension, the 2.x print statement versus the 3.x print function, and even how to generate documentation for your code using PyDoc. For those learning Python, and even for those who choose to use this book as a reference, this section will be greatly used.
Perhaps one of the most significantly changed sections between the two editions of Learning Python (again, noting that I’ve never looked at the 4th Edition so I don’t know how significant a change it is between the 4th and 5th editions), is what was “Functions” in the 3rd edition is now “Functions and Generators” in the 5th Edition. There is a significant overhaul between the two: where before “Scopes and Arguments” were a single chapter, we now have two chapters, one devoted to each topic; the 33 page chapter has turned into 67 pages spanning two chapters. It also goes into great detail about generator functions and expressions (something I have yet to fully explore). Suffice it to say, there is a good 45 pages of new content here that will prove interesting to read (list comprehension, generators, etc.).
The fifth section, “Modules and Packages” likewise contains greatly expanded content covering the use of modules, how to create them, why (and how) you should use them, the differences between importing and reloading modules, full coverage of Python 3.3 namespace packages, problems you can encounter with module use, and so forth. It talks about the features common to both major versions of Python, and has sections that are more specific, such as how byte code is handled (.pyc in versions prior to 3.2 and the pycache directory in 3.2+) and namespace packages that were introduced in 3.3 (which is also shows the differences between regular packages and namespace packages). This once again shows the level of detail the book provides for users of any version of Python.
Section six is all about Object-Oriented Programming and classes, and gives great detail and examples on topics such as polymorphism, classes and subclasses, object handling, operator overloading, and more.
Section seven goes into the how’s and why’s of exceptions and how to use them to write good error-handling in your code. This is the last section that appears in both editions, although (as with every other section), this one is greatly expanded.
The new section in the 5th Edition, compared to the 3rd, is the “Advanced Topics” section and its five chapters. This section goes into unicode and byte strings — an area that has seen a lot of changes between Python 2.x and 3.x, as well as managed attributes, decorators for functions and classes, metaclasses and the differences between them.
Obviously I’ve not yet read the entire book and chances are I never will. Most of these programming books I never do read end-to-end, but I do use them as functional references and to learn new things from (pretty much the entire “Advanced Topics” section is new to me), as well as to brush up on older things. From the parts I’ve read, and the comparisons I’ve made to the 3rd edition, this is most definitely a worthwhile “upgrade”. One thing I appreciate as well is the consistent back-and-forth regarding Python 2.x versus 3.x. As a Python coder who has never yet touched Python 3.x, this book will help me understand the subtle, and sometimes not-so-subtle, nuances between both major versions — when the time comes (aka: when the time is available). As such, this book is valuable to me now (writing code in Python 2.x) and will be valuable to me in the future.
I certainly appreciate the expanded content, as it’s already twigged a few things in my mind about the code I’ve written so far, and has given me some new ideas on how to handle certain issues or improve performance/handling of my code. This is both good and dangerous! Having said that, this is most definitely a book worth getting for any Python programmer who either is new to the language or is a veteran of the language — the first will appreciate the no-nonsense easy-to-understand approach to introducing both the basics and some quite advanced topics, while the latter will appreciate it as a reference book or to expand on their understanding of certain topics. For myself, I’m somewhere in the middle of the two and this book is introducing me to a lot of stuff I do not yet know, and is a very handy reference for the stuff that I do know (and need reminders of every once in a while).
I’ve highly recommended the 3rd edition of this book to anyone asking about good books on Python, and the 5th Edition is no different. I highly recommend this book to anyone who wants more than just a passing understanding of Python.
And as a replacement for my well-worn and well-loved 3rd Edition, I know this book will see much use from me.