Conditionals — Boolean Expressions

The Boolean values true and false often result from the evaluation of comparison operators (using Python notation): <, <=, ==, !=, >=, >; for less than, less than or equal to, equal to, not equal to, greater than or equal to, and greater than.  These binary operators return true if their two operands are in the given order. The logical operators are not, and, and or. The not operator returns the opposite value of the operand (e.g. !a has the opposite value of a). The and operator returns true if and only if both operands are true. The or operator returns true if one or both of the operands are true.

Examples of comparison operators:

x < y #true if x is less than y, else false a >= b #true if a is greater than or equal to b, else false
x != y # true if x is not equal to y, else false

Examples of logical operators:

a = true
b = false

!a #false because !true = false
a and b #false because true and false = false
a and !b #true because both operands are true
a or b #true because true or false = true
!a or b #false because false or false = false
!(a and b) #true 

Most textbooks that discuss Boolean expressions use truth tables to show how each of the Boolean operators combines the true/false value operands to produce a Boolean result. Check out http://openbookproject.net/thinkcs/python/english3e/conditionals.html for more information about boolean expressions, including examples of truth tables.

The following video gives an overview of Boolean expressions, including the basic definition of the Boolean data type: the set of values { true, false } and the set of operations { and, or, not }. Video Length: 6:58