What is Boolean logic?
programSequences of instructions for a computer. use simple comparisons to help make decisions. Boolean logicA form of logical algebra which works only with two values, true or false. is a form of algebra where all valueA numerical amount denoted by a specific term, eg the value of x is 10. are either True or False. These values of true and false are used to test the conditionIn computing, this is a statement or sum that is either true or false. A computation depends on whether a condition equates to true or false. that selectionA decision within a computer program when the program decides to move on based on the results of an event. and iterationIn computer programming, this is a single pass through a set of instructions. are based around.
Boolean logic uses algebra and algebraic expressions. We use these expressions in algorithms and programs.
Expression | Boolean equivalent |
Equals | = |
Greater than | > |
Less than | < |
Greater than or equal to | >= |
Less than or equal to | <= |
Does not equal | <> |
And | AND |
Or | OR |
Not | NOT |
Expression | Equals |
---|---|
Boolean equivalent | = |
Expression | Greater than |
---|---|
Boolean equivalent | > |
Expression | Less than |
---|---|
Boolean equivalent | < |
Expression | Greater than or equal to |
---|---|
Boolean equivalent | >= |
Expression | Less than or equal to |
---|---|
Boolean equivalent | <= |
Expression | Does not equal |
---|---|
Boolean equivalent | <> |
Expression | And |
---|---|
Boolean equivalent | AND |
Expression | Or |
---|---|
Boolean equivalent | OR |
Expression | Not |
---|---|
Boolean equivalent | NOT |
Most programming languages use these equivalent Boolean expressions. However, some, such as PythonA high-level programming language., have slightly different equivalents:
Expression | Boolean equivalent | In Python |
Equal to | = | == |
Does not equal | <> | != |
And | AND | and |
Or | OR | or |
Not | NOT | not |
Expression | Equal to |
---|---|
Boolean equivalent | = |
In Python | == |
Expression | Does not equal |
---|---|
Boolean equivalent | <> |
In Python | != |
Expression | And |
---|---|
Boolean equivalent | AND |
In Python | and |
Expression | Or |
---|---|
Boolean equivalent | OR |
In Python | or |
Expression | Not |
---|---|
Boolean equivalent | NOT |
In Python | not |