×

python · level 1 · unit 4 · lesson 1

  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

An if runs code only when its is True.

Picture a fork in the path with a sign: Is it Saturday? An if asks a condition like that. If the answer is yes, Python takes the path and runs the lines inside. If not, it walks straight past.

Python answers every condition with True or False. A value that can only be one of these two is a . To ask whether two values match, use two equals signs, ==. One = puts a value in a box.

The if line ends with a colon. The lines inside start with four spaces. That tells Python which lines belong to the if.

day = "Saturday"
print(day == "Saturday")
if day == "Saturday":
    print("Pancakes for breakfast!")
print("Time to get dressed.")

Lines without indentation sit outside the if, so they run every time.