© Paul Gerrard 2016
Paul GerrardLean Python10.1007/978-1-4842-2385-7_3

3. Program Structure

Paul Gerrard
(1)
Maidenhead, Berkshire, UK
 

Decision Making

Some simple utilities might be a short list of statements run in order, but a useful program usually needs to make decisions and choices. The decision making in a program determines the path that the program takes. Decisions are made by if statements.

The if Statement

if statements depend on some form of test or condition. The normal format of an if statement is shown here:
if test:               # note the colon ':'.
   statement1          # The statements following the
   statement2          # if are indented and executed
   statement3          # if the test is True.
In this case, the three statements ...

Get Lean Python: Learn Just Enough Python to Build Useful Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.