if statement
The statement that runs a block of code only when a condition is true.
An if statement is the most common conditional: it tests a Boolean condition and runs the indented block beneath it only when that condition is True. Add elif for extra cases and else for the fallback.
temperature = 30
if temperature > 25:
print("Warm")
else:
print("Cool")
Output
Warm
Where this shows up in real Python
If statements guard risky actions, pick between options, and check results throughout every real program.
if / elif / else
if condition:— run a block conditionallyelif other:— test another caseelse:— the fallback branchif x and y:— combine conditions
Official documentation: Python Tutorial: if Statements