Computer programs are built with two essential features: data and
processing. We started with processing elements of Python. We're about to
start looking at data structures.
In Part I, “Language Basics”, we introduced almost all of the
procedural elements of the Python language. We started with expressions,
looking at the various operators and data types available. We described
fourteen of the 21 statements that make up the Python language.
Expression statements - for example, a function evaluation
where there is no return value.
The import statement - used to include a
module into another module or program.
The print statement - used to provide
The assignment statements, from simple to
augmented - used to set the type and value of a variable.
The del statement - used to remove a
variable, function, module or other object.
The if statement - for conditionally
performing suites of statements.
The pass statement - which does nothing,
but is a necessary placeholder for an if or while suite that is
The assert statement - used to confirm the
program is in the expected state.
The for and while
statements - for performing suites of statements using a sequence of
values or while a condition is held true.
The break and continue
statements - for short-cutting loop execution.
The def statement - used to create a
The return statement - used to exit a
function, possibly providing the return value.
The Other Side of the Coin. The next chapters focus on adding various data types to the basic
Python language. The subject of data representation and data structures
is possibly the most profound part of computer programming. Most of the
killer applications - email, the world wide web,
relational databases, are basically programs to create, read and
transmit complex data structures.
We'll work our way through the following data structures.
Sequences. In Chapter 11, Sequences: Strings, Tuples and Lists we'll extend our knowledge of
data types to include an overview various kinds of sequences:
strings, tuples and lists. Sequences are collections of objects
accessed by their numeric position within the collection.
In Chapter 12, Strings we describe the
string subclass of sequence. The exercises
include some challenging string manipulations.
In Chapter 14, Lists we describe the
variable-length sequence, called a list. This
list sequence is one of the powerful features that
sets Python apart from other programming languages. The exercises
at the end of the list section include both simple
and relatively sophisticated problems.
Mappings. In Chapter 15, Mappings and Dictionaries we describe mappings and
dictionary objects, called dicts. We'll show
how dictionaries are part of some advanced techniques for handling
arguments to functions. Mappings are collections of value objects
that are accessed by key objects.
Sets. We'll cover set objects in Chapter 16, Sets. Sets are simple collections of unique objects
with no additional kind of access.
Exceptions. We'll cover exception objects in Chapter 17, Exceptions. We'll also show the exception handling
statements, including try,
except, finally and
raise statements. Exceptions are both simple data
objects and events that control the execution of our
Iterables. The yield statement is a variation on
return that simplifies certain kinds of generator
algorithms that process or create create
iterable data structures. We can iterate
through almost any kind of data collection. We can also define our
own unique or specialized iterations. We'll cover this in Chapter 18, Generators and the yield Statement.