CHAPTER 5

image

Conditional Statements

Conditional statements are an important part of many programs. They allow logic control of our programs. There are three main conditional statement types in Python. If / Elif / Else conditionals, For loops and While loops.

IF / ELIF / ELSE Statements

The if statements allow us to check the truth of a statement or statements and apply logic to the various possibilities. The if statement is simple at its heart.

if (statement) :    # do the following code    # do this line as well# This line is NOT part of the if statement.

The statement starts with the 'if' keyword (the 'if' must be in lowercase) followed by the ...

Get The Python Quick Syntax Reference 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.