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 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.