Python if ... else Statement

The if ... else statement executes a group of statements when a condition is True; otherwise, it will execute another group of statements.

The syntax of if ... else statement is given below:

Flowchart of Python if... else Statement

If else Statement Flow

Short Hand If ... Else

If you have only one statement to execute, one for if, and one for else, you can put it all on the same line:

Example

One line if else statement: