Arithmetic Operators
We'll cover the following...
Arithmetic Operators
Name | Symbol | Syntax | Explanation |
+ | Addition |
|
|
- | Subtraction |
|
|
* | Multiplication |
|
|
/ | Division |
| The quotient of |
// | Floor Division |
| The quotient of |
** | Exponent / Power |
|
|
% | Modulo |
| The remainder when |
For demonstration purposes, let’s take two numbers: num_one, which will be made equal to 6, and num_two, which will be made equal to 3. Applying the operations above would give the following results:
Addition
Adding 6 and 3 would result in 9.
Expression: 6 + 3
Subtraction
Subtracting 3 from 6 would result in 3.
Expression: 6 - 3
Multiplication
Multiplying 6 and 3 would result in 18.
Expression: 6 * 3
Division
Dividing 6 by 3 using the / operator would result in 2.0 (always a float).
Expression: 6 / 3
Floor division
Dividing 6 by 3 using the // operator would result in 2 (since 6 and 3 are integers).
Expression: 6 // 3
Power
6 to the power of 3 would result in 216.
Expression: 6 ** 3
Modulo
6 divided by 3 would result in a remainder of 0.
Expression: 6 % 3
Code
We can effectively put this into Python code, and you can even change the numbers and experiment with the code yourself! Click the “Run” button to see the output.