Chapter 8. Conditionals and Loops

The primary focus of this chapter are Python’s conditional and looping statements, and all their related components. We will take a close look at if, while, for, and their friends else, elif, break, continue, and pass.

8.1 if Statement

The if statement for Python will seem amazingly familiar. It is made up of three main components: the keyword itself, an expression that is tested for its truth value, and a code suite to execute ...

Get Core Python Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.