Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Programming Fundamentals

The common Boolean operators AND, OR and NOT

All topicsPractise exam questions
Knowledge organiser

Programming Fundamentals

2.2.1f

== != <> <= >= < > '

What you need to know

Boolean operators (AND, OR, NOT) work with Boolean values (True/False) and are used in conditions to control program flow. Comparison operators (==, !=, <, >, <=, >=) compare values and return True or False. These are combined in selection and iteration statements to create complex conditions.

Key points

  • AND returns True only if BOTH conditions are True.
  • OR returns True if EITHER condition (or both) is True.
  • NOT reverses a Boolean value: NOT True = False, NOT False = True.
  • == checks if two values are equal; != checks if they are not equal.
  • < less than, > greater than, <= less than or equal to, >= greater than or equal to. Use >= not ≥ in code.
  • Boolean operators can be combined: e.g. if A AND (B OR C) → customer is 15+ AND has ticket OR has money.
  • Common Mistake:if room == "basic" or "premium" is WRONG. You must compare the variable each time: if room == "basic" or room == "premium".
  • Common Mistake:Checking for invalid input with OR can be wrong. e.g. if room != "basic" or room != "premium" is always True. Use AND instead: if room != "basic" and room != "premium".
  • Exam Tip:Pay careful attention to AND vs OR. Check validity with AND (both conditions must hold), check invalidity with OR (either condition fails).
  • Common Mistake:Operator precedence — AND is evaluated BEFORE OR (like BIDMAS). if SystemArmed AND DoorActive OR WindowActive will sound the alarm when the window is active even if the system is NOT armed! Fix with BRACKETS: if SystemArmed AND (DoorActive OR WindowActive).
  • Exam Tip:== is a COMPARISON operator, + is ARITHMETIC, DIV is ARITHMETIC, > is COMPARISON. You may be asked to classify operators.
  • These operators are essential for writing conditions in if statements and while loops.

Code examples

Boolean and comparison operators
python
age = 20
has_ticket = True

# AND: both must be True
if age >= 18 and has_ticket:
    print("Entry allowed")

# OR: at least one must be True
if age < 12 or age > 65:
    print("Discount applies")

# NOT: reverses the value
logged_in = False
if not logged_in:
    print("Please log in")