×

python · level 1 · unit 4 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

is the other path at the fork.

An if on its own either runs its lines or skips them. Often you want a plan B. else means otherwise: when the condition is False, Python runs the lines under else instead.

At a fork you always take exactly one path. With if and else, exactly one set of lines runs. Never both, and never neither.

else sits right under its if, lined up on the left. It has no condition of its own, but it still needs a colon, and its lines are indented.

biscuits = 0
if biscuits == 0:
    print("Time to go to the shop.")
else:
    print("Have a biscuit!")

Read else as "otherwise".