Practice with Relational and Logical Operators

4. Truth Tables

There is a lot to learn about the logic branch of mathematics, but we can selectively learn some of it to improve our algorithmic thinking when programming.

Below are truth tables for the comparison operator ==, and each of the logic operators and or , and not . While you may be able to reason them out, it can also be helpful to work to memorize them as that can make your programming decision-making process quicker.

== Truth Table
x == y Returns
True == True True
True == False False
False == True False
False == False True

AND Truth Table
x and y Returns
True and True True
True and False False
False and True False
False and False False

OR Truth Table
x or y Returns
True or True True
True or False True
False or True True
False or False False

NOT Truth Table
not x Returns
not True False
not False True

Truth tables are common mathematical tables used in logic, and are useful to memorize or keep in mind when constructing algorithms (instructions) in computer programming.