Introduction
Python syntax is designed to be very simple. There are a few rules; we'll look at some of the interesting statements in the language as a way to understand those rules. Just looking at the rules without concrete examples can be confusing.
We'll cover some basics of creating script files first. Then we'll move on to looking at some of the more commonly-used statements. Python only has about twenty or so different kinds of imperative statements in the language. We've already looked at two kinds of statements in Chapter 1, Numbers, Strings, and Tuples: the assignment statement and the expression statement.
When we write something like this:
>>> print("hello world")hello world
We're actually executing a statement that contains only the evaluation of a function, print()
. This kind of statement—where we evaluate a function or a method of an object—is common.
The other kind of statement we've already seen is the assignment statement. Python has many variations on this theme. Most...