Python · Stage 2 – Doing Things with Values · Lesson 16 of 50

Logical Operators

Combine or reverse True and False values using and, or, and not.

and is True only when both sides are True. Think: “I need a ticket AND identification.”

allowed = True and False
Line-by-line explanation
  1. The left value is True.
  2. and requires both sides to be True.
  3. The right value is False.
  4. The result is False.

or is True when at least one side is True. not reverses one boolean.

offline = not True
Line-by-line explanation
  1. True is the starting value.
  2. not reverses it.
  3. offline stores False.