Course Home
Check Yourself
Python Errors in English
CodeSkulptor FAQ

Online Lessons

Related Links

Online Development




Truth Tables

The Python interpreter doesn't think about operators the way we do when we do math. For example, when a human sees an equation like this:

x = 2 + 3

It looks like the description of a situation. A person might interpret this equation as something like "The variable x has the same value as the sum of 2 and 3". A human might want to solve for x, or might not. A human might get the answer wrong one day and then get then answer right another day.

For the Python interpreter, the statement is a procedure that must be carried out. To Python, the statement means "Find the sum of 2 and 3 and assign that value to the variable x". Every time Python is given the same statement, it will give the same answer.

The Python interpreter thinks of addition as a mini-machine that takes two numbers and uses them to produce another number, like this:


When it comes to inequality symbols, things really get weird. In math, we're used to seeing inequalities like this:

2 > 3

We recognize this as a false statement. So does Python. But remember our adding machine above? It takes two numbers and produces another number. As far as Python is concerned, there is also a mini-machine for > that takes two numbers and produces a bool (True or False). So you can actually write things like this:

x = 2 > 3

Here the > operator converts the 2 and the 3 into a bool value (False) and assigns that value to x.

For Python, the > is considered to be an operator, just like the +. The only difference is that the + takes two numbers and produces another number, while the > takes two numbers and produces a bool. In Pythonese, the + is called an arithmetic operator, and the > is called a comparison operator.


Notice in the figure above that there is also an operator called a boolean operator that takes two bool values and produces another bool value. The video below explains the boolean operator and builds truth tables using the operators and and or.

Watch the videos and follow along in the console

Then use the quizlet below to make sure the boolean expressions are committed to memory.

Quizlet Live Study Material


Try this quiz on boolean operations.

Coding Practice

In the trinket below, you'll start with a def for a method called sleep_in. The function takes two arguments, weekday and vacation.

  1. Remove the comment and pass statement. You'll replace this with your own code. Remember to indent your statements correctly!
  2. Use not and or to write a correct expression with weekday and vacation and return the result.
  3. Click the right-facing triangle button to test your code.
  4. Click the pencil button as needed to get back to your code.
  5. Send a link to your solution to

Review Material

Leone Learning Systems, Inc. (LLS) is a North Shore company that provides online courses for kids anywhere and local teaching and tutoring services for students in Chicago and the Northern Suburbs of Chicagoland. LLS also provides a free geometry software package for children age 6 and up, and free resources for teachers and parents. This site includes information about classes taught, availability for tutoring, learning activities for kids, lesson plans, and ongoing software and curriculum research and development efforts.