The mathematician George Boole studied the algebra of statements that contain only true and false. In Boolean algebra there are three basic operators; 1) addition known as or, 2) multiplication known as and, and 3) the compliment known as not. This chapter will show how to write and understand Boolean expressions in Python.

Objectives

Upon completion of this chapter’s exercises, you should be able to:

  • Explain the meaning of the Boolean values and the ways that they may be represented in a Python program.
  • Compute a Boolean expression using the operations of AND, OR, and NOT.
  • Produce a truth table given a Boolean expression with variables.
  • Create Boolean expressions in a Python program.
  • Use the comparison operators to compare two values.
  • Create complex comparisons between several values using comparison operators and Boolean operators in a Python program.