| variable/property = | Variable or Property or Constant or Expression |
An expression is a combination of variables/property values/constants called operands separated by operators.
Operators are symbols used to tell the computer what to do.
There are several different types of operators
^ Exponentiation (Binary operator - applied to two operands)
- Negation (Unary operator - applied to one operand)
* Multiplication (Binary operator)
/ Division (Binary operator)
\ Integer Division (Binary operator)
Mod Modulus Division (Binary operator)
+ Addition (Binary operator)
- Subtraction (Binary operator)
As you can see there are three different division operators.
The following are examples of expressions
We can combine multiple operators and operands in one expression
What is the result of the following expression?
decAnswer = 6 – 3 * 6 / 9
The computer evaluates expression based on a set of rule called the hierarchy of operations or order of precedence which is the same order of precedence you learned in math class. We can alter the order of precedence by using parenthesis
decAnswer = (6 – 3) * (6 / 9)