runtime
13 / 250
lesson 13 Operators & Expressions · beginner

And, or, and not

and, or, and not combine True and False into one answer.

You'll be able to
  • Use and when both sides must be True
  • Use or when either side may be True
  • Use not to flip True and False
The idea

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.

example-1.py · Both, either, and the opposite
print(True and False)
print(True or False)
print(not True)
print(not False)
example-2.py · Two comparisons at once
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.

Review
  • 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.
Practise this

Loading your progress…

To master this lesson, solve both challenges without hints or the answer, and pass the concept check.

And, or, and not — Operators & Expressions · Runtime