And, or, and not
and, or, and not combine True and False into one answer.
- Use and when both sides must be True
- Use or when either side may be True
- Use not to flip True and False
Real rules have more than one part: free delivery if the total is at least 50 or you are a member; a game goes ahead if it is warm enough and not raining. and is True only when both sides are True. or is True when either side is True. not flips one value: not True is False, and not False is True.
These words work on True and False. They are not the arithmetic operators.
Run each example to see what it prints. Running examples doesn't count toward progress.
print(True and False) print(True or False) print(not True) print(not False)
price = 12 print(price > 10 and price < 20) print(price < 10 or price == 12)
Mistake to avoid: write the name on both sides. price > 10 and < 20 is a syntax error; it has to be price > 10 and price < 20. And pick the word from the rule: "both must hold" is and, "any one is enough" is or.
- and is True only when both sides are True.
- or is True when at least one side is True. not flips True and False.
- Write the name on both sides of a range. Next: in and is.