General Notes
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 |
|---|---|---|---|
+ | Addition | Adds together two values | a + b |
- | Subtraction | Subtracts one value from another | a - b |
* | Multiplication | Multiplies two values | a * b |
/ | Division | Divides one value by another | a / y |
% | Modulus | Returns the division remainder | a % y |
** | Exponent | Returns a to the power of b | a ** b |
// | Floor Divide | Divide & return the whole number | a // b |
Assignment operators
| Operator | Example |
|---|---|
= | a = 5 |
<operator>= | a += 5 (Represents a = a + 5) |
Comparison operators
Returns a boolean value
| Python | Description |
|---|---|
var == var | Equal to |
var != var | Not Equal |
<, >, <=, >= | Greater/Less than (or equal to) |
Logical operators
Works similar to logic gates
| Operator | Name | Example |
|---|---|---|
and | Logical and | a > 9 and a < 25 |
or | Logical or | a > 9 or a < 25 |
not | Logical 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 |
