Arithmetic Operators
What are Arithmetic Operators
Arithmetic operators are symbols that performs mathematical operations
There are seven arithmetic operators in Python
Here is an overview of arithmetic operators
Operator | Description | Example |
---|---|---|
+ | Addition | x + y = 30 |
- | Substraction | x - y = 10 |
- | Multiplication | x * y = 200 |
- | Division | x / y = 2.0 |
- | Floor Division | x // y = 2 |
- | Exponent | x ** y = 4 # if x = 2, y = 2 |
% | Modulus | x % y = 0 |
Addition Operator
Addition operator represented by +
adds the object(value) on its left with object(value) on its right and then returns the result
Example
>>> >>> # >>> 5 + 9 14 >>> >>> >>> >>>
Subtraction Operator
Substraction operator symbolised by -
subtracts the value on its right from the value on its left and then returns the result.
Example
>>> >>> # >>> 11 - 9 2 >>> >>> >>> >>>
Multiplication Operator
Multiplication operator represented by *
multiplies the operand(value) on its left by the value or object on its right, and returns the result.
Example
>>> >>> 10 * 5 50 >>> >>> >>> >>> >>>
Division Operator
Division operator represented by /
divides the value or object on the its left by the operand(value) on its right, and then returns the result.
Example
>>> >>> >>> 30 / 3 10.0 >>> >>> >>> >>> >>>
Floor Division Operator
Floor Division operator represented by //
divides the value or object on the its left by the operand(value) on its right, and then returns the result by discarding the floating points.
Example
>>> >>> 30 // 3 10 >>> >>> 10 // 3 3 >>> >>>
Exponentiation Operator
Example
>>> >>> 5 ** 2 25 >>> >>> 2 * 5 32 >>> >>> >>>
Modulus Operator
Modulus operator represented by %
divides the value or object on the its left by the operand(value) on its right, and then returns the remainder.
Example
>>> >>> 20 % 10 0 >>> >>> 10 % 3 1 >>> >>> >>>