Datasheet

Chapter 1: A Python Primer
8
For example, if you type
:
Print 12 + 15
into the Python interpreter, you ll get the following output:
> > > print 12 + 15
27
> > >
This is because you told the system to print the result of the expression 12 + 15, which is a complete
statement.
However, if you type
:
print 12 +
you ll get a syntax error, as shown here:
> > > print 12 +
SyntaxError: invalid syntax
> > >
Clearly, the system cannot read this because it isn t a complete statement, so it results in an error.
Multi - line Statements
It is possible to have a single statement span multiple lines. You could do this for aesthetic reasons or
simply because the line is too long to read on one screen. To do this, simply put a space and a backslash
at the end of the line. Here are a few examples:
name = “Jim \
Knowlton”
sum = 12 + \
13
Iteration and Decision - Making
There are two basic ways to control the flow of a program: through iteration (looping) and through
decision - making.
c01.indd 8c01.indd 8 6/2/08 12:03:10 PM6/2/08 12:03:10 PM