Summary
In this chapter, we explored Python’s basic procedural statements:
Assignments store references to objects.
Expressions call functions and methods.
printsends text to the standard output stream.if/elif/elseselects between one or more actions.while/elseloops repeat an action until a test proves false.for/elseloops step through the items in a sequence object.breakandcontinuejump around loops.passis an empty placeholder.
We also studied Python’s syntax rules along the way, looked at Boolean operators and truth tests, and talked a little about some general programming concepts in Python.
By combining basic statements, we are able to code the basic logic needed to process objects. In Chapter 4, we move on to look at a set of additional statements used to write functions, which package statements for reuse. In later chapters, we’ll see more statements that deal with bigger program units, as well as exceptions. Table 3.5 summarizes the statement sets we’ll be studying in the remaining chapters of this part of the book.
Table 3-5. Preview: Other Statement Sets
|
Unit |
Role |
|---|---|
|
Functions |
Procedural units |
|
Modules |
Code/data packages |
|
Classes |
New objects |
|
Exceptions |
Errors and special cases |