O'Reilly logo

The Python Quick Syntax Reference by Gregory Walters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required