What this book covers
Chapter 1, Getting Started, addresses installing or upgrading Python. We explore Python's Read-Evaluate-Print Loop (REPL) as a way to interact with the language. We'll use this interactive Python mode as a way to explore most of the language features.
Chapter 2, Simple Data Types, introduces a few features concerning numbers and some simple collections. We'll look at Python's Unicode strings as well as byte strings, including some of the conversions between strings and numbers.
Chapter 3, Expressions and Output, provides more details on Python expression syntax and how the various numeric types relate to each other. We'll look at the coercion rules and the numeric tower. We'll look at the print()
function, which is a common tool for looking at output.
Chapter 4, Variables, Assignment and Scoping Rules, shows how we assign names to objects. We look at a number of different assignment statements available in Python. We also explore the input()
function, which parallels the print()
function.
Chapter 5, Logic, Comparisons, and Conditions, shows the logical operators and literals that Python uses. We'll look at the comparison operators and how we use them. We'll look closely at the if
statement.
Chapter 6, More Complex Data Types, shows the core features of the list
, set
, and dict
built-in types. We use the for
statement to work with these collections. We also use functions such as sum()
, map()
, and filter()
.
Chapter 7, Basic Function Definitions, introduces the syntax for the def
statement as well as the return
statement. Python offers a wide variety of ways to provide argument values to functions; we show a few of the alternatives.
Chapter 8, More Advanced Functions, extends the basic function definitions to include the yield statement. This allows us to write generator functions that will iterate over a sequence of data values. We look at a few functional programming features available via built-in functions as well as the modules in the Python Standard Library.
Chapter 9, Exceptions, shows how we handle and raise exceptions. This allows us to write programs which are considerably more flexible. A simple "happy path" can handle the bulk of the processing, and exception clauses can handle rare or unexpected alternative paths.
Chapter 10, Files, Databases, Networks, and Contexts, will introduce a number of features related to persistent storage. We'll look at Python's use of files and file-like objects. We'll also extend the concept of persistence to include some database features available in the Python Standard Library. This chapter will also include a review of the with
statement for context management.
Chapter 11, Class Definitions, demonstrates the class
statement and the essentials of object-oriented programming. We look at the basics of inheritance and how to define class-level (static) methods.
Chapter 12, Scripts, Modules, Packages, Libraries, and Applications, shows different ways in which we can create Python code files. We'll look at the formal structures of script, module, and package. We'll also look at informal concepts such as application, library, and framework.
Chapter 13, Metaprogramming and Decorators, introduces two concepts that can help us write Python code that manipulates Python code. Python makes metaprogramming relatively simple; we can leverage this to simplify certain types of programming where a common aspect doesn't fit neatly into a class hierarchy or library of functions.
Chapter 14, Fit and Finish – Unit Testing, Packaging, and Documentation, moves beyond the Python language into the idea of creating a complete, polished product. Any well-written program should include test cases and documentation. We show common ways to make sure this is done properly.
Chapter 15, Next Steps, will demonstrate four simple kinds of applications. We'll look at the command-line interface (CLI), graphic user interface (GUI), simple Web frameworks, as well as MapReduce applications.