Course Home Online Lessons
Related LinksOnline DevelopmentLessonsReferenceeBooks |
Truth TablesThe 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 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
QuizTry this quiz on boolean operations. Coding PracticeIn the trinket below, you'll start with a
Review Material
|