2 Statements and Syntax

Python syntax is designed to be simple. In this chapter, we’ll look at some of the most commonly used statements in the language as a way to understand the rules. Concrete examples can help clarify the language’s syntax.

We’ll cover some of the 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 20 or so different kinds of imperative statements in the language. We’ve already looked at two kinds of statements in Chapter 1, 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,

Get Modern Python Cookbook - Third Edition 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.