Boolean Logic

--Originally published at Carolina's Blog Site

 

The logic that computers use is called Boolean logic, so called because it was invented by George Boole way back in the 1800s.

There are two Boolean values: True and False. I know, shocker.

  • They can be created by comparing values, for example using the equal operator ==, the not equal operator !=, the greater than operator, etc.
  • Btw, DO NOT confuse assignment (=) with comparison (==).
  • Python’s Boolean operators are and, or, and not.
    • And: Takes 2 arguments. It evaluates to True if both are True.
    • Or: Takes 2 arguments. It evaluates to True if either or both are True.
    • Not: Takes 1 argument, and inverts it. The result of not True is False, and not False goes to True.

 

Anyway, operator precedence is a very important. Python’s order of operations is the same as that of normal math: Please Excuse My Dear Aunt Sally.

.