Home / Python / Day 2: Control Flow / If / Else Statements

If / Else Statements

Conditional statements let your program make decisions based on conditions.

Conditional Statements

Conditional statements execute different code depending on whether a condition is True or False.

if Statement

Executes a block only if the condition is True.

if-else Statement

Executes one block if True, another if False.

if-elif-else Chain

Test multiple conditions in sequence.

Nested if

An if statement inside another if statement.

Ternary Operator

One-line if-else: x if condition else y