What This Book Is Not

Given its relatively large audience over the years, some have inevitably expected this book to serve a role outside its scope. So now that I’ve told you what this book is, I also want to be clear on what it isn’t:

Because these points are key to this book’s content, I want to say a few more words about them up front.

It’s Not a Reference or a Guide to Specific Applications

This book is a language tutorial, not a reference, and not an applications book. This is by design: today’s Python—with its built-in types, generators, closures, comprehensions, Unicode, decorators, and blend of procedural, object-oriented, and functional programming paradigms—makes the core language a substantial topic all by itself, and a prerequisite to all your future Python work, in whatever domains you pursue. When you are ready for other resources, though, here are a few suggestions and reminders:

Reference resources

As implied by the preceding structural description, you can use the index and table of contents to hunt for details, but there are no reference appendixes in this book. If you are looking for Python reference resources (and most readers probably will be very soon in their Python careers), I suggest the previously mentioned book that I also wrote as a companion to this one—Python Pocket Reference—as well as other reference books you’ll find with a quick search, and the standard Python reference manuals maintained at http://www.python.org. The latter of these are free, always up to date, and available both on the Web and on your computer after a Windows install.

Applications and libraries

As also discussed earlier, this book is not a guide to specific applications such as the Web, GUIs, or systems programming. By proxy, this includes the libraries and tools used in applications work; although some standard libraries and tools are introduced here—including timeit, shelve, pickle, struct, json, pdb, os, urllib, re, xml, random, PyDoc and IDLE—they are not officially in this book’s primary scope. If you’re looking for more coverage on such topics and are already proficient with Python, I recommend the follow-up book Programming Python, among others. That book assumes this one as its prerequisite, though, so be sure you have a firm grasp of the core language first. Especially in an engineering domain like software, one must walk before one runs.

It’s Not the Short Story for People in a Hurry

As you can tell from its size, this book also doesn’t skimp on the details: it presents the full Python language, not a brief look at a simplified subset. Along the way it also covers software principles that are essential to writing good Python code. As mentioned, this is a multiple-week or -month book, designed to impart the skill level you’d acquire from a full-term class on Python.

This is also deliberate. Many of this book’s readers don’t need to acquire full-scale software development skills, of course, and some can absorb Python in a piecemeal fashion. At the same time, because any part of the language may be used in code you will encounter, no part is truly optional for most programmers. Moreover, even casual scripters and hobbyists need to know basic principles of software development in order to code well, and even to use precoded tools properly.

This book aims to address both of these needs—language and principles—in enough depth to be useful. In the end, though, you’ll find that Python’s more advanced tools, such as its object-oriented and functional programming support, are relatively easy to learn once you’ve mastered their prerequisites—and you will, if you work through this book one chapter at a time.

It’s as Linear as Python Allows

Speaking of reading order, this edition also tries hard to minimize forward references, but Python 3.X’s changes make this impossible in some cases (in fact, 3.X sometimes seems to assume you already know Python while you’re learning it!). As a handful of representative examples:

  • Printing, sorts, the string format method, and some dict calls rely on function keyword arguments.

  • Dictionary key lists and tests, and the list calls used around many tools, imply iteration concepts.

  • Using exec to run code now assumes knowledge of file objects and interfaces.

  • Coding new exceptions requires classes and OOP fundamentals.

  • And so on—even basic inheritance broaches advanced topics such as metaclasses and descriptors.

Python is still best learned as a progression from simple to advanced, and a linear reading here still makes the most sense. Still, some topics may require nonlinear jumps and random lookups. To minimize these, this book will point out forward dependencies when they occur, and will ease their impacts as much as possible.

Note

But if your time is tight: Though depth is crucial to mastering Python, some readers may have limited time. If you are interested in starting out with a quick Python tour, I suggest Chapter 1, Chapter 4, Chapter 10, and Chapter 28 (and perhaps 26)—a short survey that will hopefully pique your interest in the more complete story told in the rest of the book, and which most readers will need in today’s Python software world. In general, this book is intentionally layered this way to make its material easier to absorb—with introductions followed by details, so you can start with overviews, and dig deeper over time. You don’t need to read this book all at once, but its gradual approach is designed to help you tackle its material eventually.