2.2.1 The if Statement
The if statement is the most basic form of conditional execution in Python.
It runs a block of code only when a condition evaluates to True.
How the if Statement Works
An if statement:
- Evaluates a condition
- Executes the indented code block if the condition is True
- Skips the block if the condition is False
Indentation defines the scope of the conditional block.
Condition Requirements
- The condition must evaluate to a boolean value
- Comparison and logical expressions are commonly used
- Complex conditions can be built using logical operators
📌 Note:
Correct indentation is required forifstatements to work properly.