Image of Derek the therapy dog.
What is printed in the program?

derek_is_happy = True
if derek_is_happy:
print("True")
else:
print("False")

Notice that only the print("True") is part of the If-statement. The print("False") is part of the else.
Choose an answer above!
  • Now that we know about conditional and logical operators, let's see how they can be used in If-statements.
  • As we have seen, if statements allow you to control the flow of execution based on a condition.
  • A condition can only ever be True or False.
  • This means Booleans, conditional operators, and logical operators can be used to create a condition for an If-statement.
  • When the condition is True, everything that is under the if statement and indented will be executed.
  • On this page, the indents will be highlighted yellow so you can easily see what is part of the If-statement.
  • Also, remember the 'else' will be executed if the If-statement fails.
  • The 'else' isn't required but is helpful when you want to execute code when the If-statement fails.