How are we supposed to evaluate if these are True or False?


#1

Question

How are we supposed to evaluate if these are True or False?

Answer

Any time we see a complicated looking expression, like -(2 ** 3) < 2 ** 2 and 100 / 2 <= 20 - 10 * 2, it can be helpful to break it down into its parts like below.

# First, look at the left side of the AND
left_half = -(2 ** 3) < 2 ** 2
left_half = -(8) < 4  # True

# Now look at the right side of the AND
right_half = 100 / 2 <= 20 - 10 * 2
right_half = 50 <= 0  # False

# Finally, we can combine these halves around the AND
# And since we know the truth value of either side, we know the end result!
bool_result = left_half and right_half  # False

You don’t need to write out new variables for each step, of course. And it’ll only get easier with practice. But mentally breaking down each side can definitely help!


FAQ: Learn Python - Conditionals & Control Flow - And