Python Arithmetic Operators
What are operators and operands? Let’s explain with a simple example: 10 + 5 = 15. In this expression, 10 and 5 are operands, and the + sign is the operator.
Suppose the variable a = 10 and the variable b = 5.
| Operator | Description | Example |
|---|---|---|
+ | Addition — adds the left operand to the right one. | a + b = 15 |
- | Subtraction — subtracts the right operand from the left one. | a - b = 5 |
* | Multiplication — multiplies the left operand by the right one. | a * b = 50 |
/ | Division — divides the left operand by the right one. | a / b = 2 |
% | Modulus — divides the left operand by the right one and returns the remainder. It can be used to check if numbers are even or odd. If the left operand is smaller than the right, the result is the left operand. | a % b = 0 |
** | Exponentiation — raises the left operand to the power of the right one. | a ** b = 100000 |
// | Floor Division — division where only the integer part of the result is returned. The fractional part is discarded. | 9 // 2 = 4, 9.0 // 2.0 = 4.0 |