Boolean operators
A BooleanA data type in computing which only has two possible values, true or false. data type is a binary variableA named storage location. The value of a variable can change that can have one of two possible values, 0 (False) or 1 (True). We can combine Booleans using Boolean operators AND, OR, NOT.
Order of operations
The rules of programming follow the same rules as maths in terms of the order in which operators are carried out.
They follow the rules of BODMAS:
BRACKETS/ORDERS/DIVIDE/MULTIPLY/ADD/SUBTRACT
Operators in brackets are carried out first, then orders like powers and roots, then division, multiplication, addition and, finally, subtraction.
For example, Order of Operations in programming a Celsius to Fahrenheit conversion:
celsius = float(input('Enter temperature celsius: '))fahrenheit = celsius * 9/5 + 32print(str(celsius) + ' = ' + str(fahrenheit))
Line 1: The user is asked to input a value. This value is stored in the Celsius variable as a float.
Line 2: BODMAS – Division (9/5 = 1.8), Multiplication (1.8 * Celsius), Addition (+32).
Line 3: Program outputs the temperature in Celsius and Fahrenheit.
| Operator | Name and description | Example |
| AND | Both operands (inputs) need to be True for the result to be True | a = 5, b = 6: a > 3 AND b > 3 = True |
| OR | If either or both of the operands are true then the result will be True | a = 5, b = 6: a >= 6 OR b >=6 = True |
| NOT | The result will be the opposite of the operand given | a = False, NOT a = True |
| == | Is equal to – the left operand is equal to the right | 2 == 2 would be True |
| <> or != | Is not equal to – the two operands are not equal | 2 != 1 would be True |
| < | Is less than – the left operand is less than the right | 3 < 6 would be True |
| > | Is greater than – the left operand is greater than the right | 2 > 5 would be False |
| <= | Is less than or equal to – the left operand is less than or equal to the right | 3 <= 4 would be True |
| >= | Is greater than or equal to – the left operand is greater than or equal to the right | 3 >= 5 would be False |
| Operator | AND |
|---|---|
| Name and description | Both operands (inputs) need to be True for the result to be True |
| Example | a = 5, b = 6: a > 3 AND b > 3 = True |
| Operator | OR |
|---|---|
| Name and description | If either or both of the operands are true then the result will be True |
| Example | a = 5, b = 6: a >= 6 OR b >=6 = True |
| Operator | NOT |
|---|---|
| Name and description | The result will be the opposite of the operand given |
| Example | a = False, NOT a = True |
| Operator | == |
|---|---|
| Name and description | Is equal to – the left operand is equal to the right |
| Example | 2 == 2 would be True |
| Operator | <> or != |
|---|---|
| Name and description | Is not equal to – the two operands are not equal |
| Example | 2 != 1 would be True |
| Operator | < |
|---|---|
| Name and description | Is less than – the left operand is less than the right |
| Example | 3 < 6 would be True |
| Operator | > |
|---|---|
| Name and description | Is greater than – the left operand is greater than the right |
| Example | 2 > 5 would be False |
| Operator | <= |
|---|---|
| Name and description | Is less than or equal to – the left operand is less than or equal to the right |
| Example | 3 <= 4 would be True |
| Operator | >= |
|---|---|
| Name and description | Is greater than or equal to – the left operand is greater than or equal to the right |
| Example | 3 >= 5 would be False |