Python supports some basic Arithmetic operators, these are +, -, *, /, %, ** and //. We can apply these operators on numbers as well as on variables to perform different operations.
Python Arithmetic Operator Examples
For example, if a=15 and b=3, then the following result of operations is given below.
Addition:
An Addition operation adds the operands using the Addition operator (+).
print(a+b)
Output:
18
Subtraction:
Subtraction operation subtracts operand on the right from the operand on the left of the Subtraction operator(-).
print(a-b)
Output:
12
Multiplication:
This operation multiplies the operands using the multiplication operator(*)
print(a*b)
Output:
45
Division:
This operation divides the operand on the left side of the division operator(/) with the operand on its right. Actually, the Division operator returns the quotient.
print(a/b)
Output:
5
Modulus:
Modulus operation divides the operand on the left side of the operator(%) with the operand on its right. The modulus operator returns the remainder.
print(a%b)
Output:
0
Floor Division:
It divides the operands and returns the quotient. This operation also removes the digits after the decimal point. If one of the operands is negative, the result is floored (i.e., rounded away
from zero towards negative infinity)
print(12//5)
Output:
2
print(12.0//5.0)
Output:
2.0
print(-19//5)
Output:
-4
Exponent:
This operation performs an exponential calculation, raising the operand on the right side of the operand on the left of the Exponent operator(**).
print(a**b)
Output:
3375
Leave a comment