Introduction

Control statements in Python differ slightly from control statements in languages such as Java, C#, and JavaScript.

Structure

The structure of how to write if/else if/else control statement in Python is as follows:

if [insert condition here (no brackets)]:
    [insert some action (no brackets)]
elif [insert condition here (no brackets)]:
    [insert some action (no brackets)]
else:
    [insert some action (no brackets)]

We can also do a ternary operator as follows:

name = "John"
valid = True if name == "John" else False