Pythondex

Tutorial

If Statements in Python

In Python, if statements allow you to execute a block of code only if a condition is True. The condition usually involves operators such as >, <, ==, !=, >=, <=.

Syntax

Example

Explanation

  • The condition age >= 18 uses the greater than or equal operator to check if age is 18 or more.
  • If it evaluates to True, the indented code block runs.
  • If False, the code block is skipped.

Another Example