Subtopic Notes
D - Operators
9-11. Data Types and Structures, Programming
Operators
- An operator is a symbol or keyword in programming that tells the computer to perform a specific operation on one or more values (called operands)
- May be used to compare types REAL/FLOAT and INTEGER
- May be used to compare types CHAR and STRING
- Case sensitive when used to compare types CHAR and/or STRING
- Cannot be used to compare two records or object
Arithmetic operators
| Operator | Name | Description | Python | Pseudocode |
|---|---|---|---|---|
+ | Addition | Adds together two values | a + b | a + b |
- | Subtraction | Subtracts one value from another | a - b | a - b |
* | Multiplication | Multiplies two values | a * b | a * b |
/ | Division | Divides one value by another | a / y | a / y |
% | Modulus | Returns the division remainder | a % y | MOD(a, b) |
** | Exponent | Returns a to the power of b | a ** b | ^ |
/ / | Floor Divide | Divide & return the whole number | a // b | DIV(a, b) |
Assignment operators
| Operator | Example | Pseudocode |
|---|---|---|
= | a = 5 | a ← 5 |
<operator>= | a += 5 (Represents a = a + 5) | Not supported |
Comparison operators
Returns a boolean value
| Python | Pseudocode | Description |
|---|---|---|
var == var | = | Equal to |
var != var | <> | Not Equal |
<, >, <=, >= | <, >, <=, >= | Greater/Less than (or equal to) |
Logical operators
Works similar to logic gates
| Operator | Name | Pseudocode | Example (Pseudocode) |
|---|---|---|---|
and | Logical and | AND | a > 9 AND a < 25 |
or | Logical or | OR | a > 9 OR a <25 |
not | Logical Not | NOT | NOT (a = 25) |
Precedence
Sets the rule on the order of operators
| Operator | Name |
|---|---|
() | Parentheses |
** | Exponent |
* / // % | Multiplication, Division, Floor Division, Modulus |
+ - | Addition, Subtraction |
== != > < <= >= | Comparison Operators |
not | Logical NOT |
and | Logical AND |
or | Logical OR |
