Pythondex

Tutorial

If-Else Statements in Python

In Python, if-else statements let you choose between two paths: one block runs if the condition is True, another runs if it is False.

Syntax

Example

Explanation

  • The condition age >= 18 is evaluated.
  • If True, the first block executes.
  • If False, the else block executes instead.

Another Example

Note: We are still using operators like > in the condition to compare values.