Menu

Logical Operators

Truth Tables

A truth table lists every possible combination of input truth values for a logical expression and the output produced for each combination. It lets you check what an expression does in every case, rather than just one example.

An expression with one input condition has two possible input combinations: True and False. With two input conditions there are four combinations. Write them systematically, such as True/True, True/False, False/True, False/False. The rows can be in any order, but each combination must appear once and no input combination should be left out, even when its output is False.

Applying the operator

Complete a truth table by applying the logical operator to each row of inputs.

  • AND outputs True only when both inputs are True.
  • OR outputs True for any row with at least one True input, including when both are True.
  • NOT has one input and outputs the opposite value.
ABA AND BA OR B
TrueTrueTrueTrue
TrueFalseFalseTrue
FalseTrueFalseTrue
FalseFalseFalseFalse

If A stands for has_key and B stands for score_at_least_100, the AND column shows that the level unlocks only in the first row, where both are True. The OR column is True in the first three rows because at least one input is True.

ANOT A
TrueFalse
FalseTrue

NOT reverses its single input, so NOT has_key is True exactly when has_key is False.

You can write truth values as True and False, or as 1 and 0. Choose one style and use it for the whole table; do not mix them, and avoid ticks or crosses.

Practise this