Programs constantly make choices: is the password right, is the player out of lives, is the basket over the free-delivery limit? Every choice comes down to a question whose answer is yes or no. In Python those answers are the values True and False, which are called booleans (after George Boole, a mathematician).
You get booleans by comparing values. These symbols are the comparison operators: == is equal to, != is not equal to, < less than, > greater than, <= less than or equal, >= greater than or equal. Note the double ==: a single = stores a value, so comparing needs two.
if runs some code only when a condition is True. Write if, the condition, and a colon. The lines underneath that belong to it are indented (pushed right, usually by four spaces). Indentation is how Python knows where the block starts and stops, so it's not optional.
temperature = 30
if temperature > 25:
print("It's hot.")
print("Drink water.")
print("Have a nice day.")
Prints
It's hot.
Drink water.
Have a nice day.
The last line isn't indented, so it isn't part of the if: it runs either way. Add else: for what to do when the condition is False, and elif (short for "else if") for more checks in between. Python tries them from the top and runs only the first block whose condition is True.
Combine conditions with and (both must be True), or (at least one must be True) and not (flips True and False).
age = 15
has_ticket = True
print(age >= 12 and has_ticket)
print(age < 5 or age > 65)
print(not has_ticket)
Prints
True
False
False
Most first errors in if statements are a missing colon or wobbly indentation. Python reports them as SyntaxError or IndentationError and points at the line.
Practice
What does this print?
print(4 >= 4)
More info
Quick reference
True / False
The two boolean values. Capital first letter.
== != < > <= >=
Compare two values. == compares, = stores.
if cond:
Runs the indented block only when cond is True.
elif cond: / else:
More checks / what to do otherwise. Only the first True block runs.