Summing up Math Operations
You have covered a lot of math in this chapter, but more importantly, you were able to expand your knowledge of working with numbers and variables and start doing some calculations with them. Table 4.1 will serve as a handy reference for the operations that were covered in this chapter:
Table 4.1. Mathematical Operators
Operator |
Definition |
Example |
+ |
Addition |
4 + 5 results in 9 |
– |
Subtraction |
5 – 4 results in 1 |
* |
Multiplication |
2 * 3 results in 6 |
/ |
Division |
5 / 2 results in 2.5 |
% |
Modulo |
5 / 2 results in 1 |
+= |
Addition assignment |
if x is 5, x += 3 changes x to 8 |
-= |
Subtraction assignment |
if x is 5, x -= 2 changes x to 3 |
*= |
Multiplication assignment |
if x is 5, x *= 3 changes x to 15 |
/= |
Division assignment |
if x is 5, x /= 2 changes x to 2.5 |
%= |
Modulo assignment |
if x is 5, x %= 2 changes x to 1 |
++ |
Increment |
if x is 5, x++ changes x to 6 |
-- |
Decrement |
if x is 5, x-- changes x to 4 |