In this tutorial, we are going to learn about what is arithmetic operators and how these operators are essential for performing mathematical calculations within python, provide clear examples to help you to understand their usage
Introduction to Arithmetic Operators
In python, Arithmetic Operators are used to calculate mathematical calculations between two operands. There are 7 Arithmetic Operators in Python that include
- addition (+)
- subtraction (-)
- multiplication (*)
- division (/)
- floor division(//)
- modulus (%)
- exponent(**)
Addition Operator
Addition operator(+) is used to add two operands. For example, a=8, b=5 then a+ b=13
a=8 b=5 c= a + b print(c)
Output:
13
Subtraction Operator
In python, Subtraction operator(-) is used to subtract second value from first value. For example, a=20, b=10 then a- b=10. If the first value is less then second value then result will be negative. For example, a=10, b=20 then a- b=10
a=10 b=5 c=a-b print(c)
output:
5
Multiplication Operator
Multiplication operator(*) is used to multiply one operand with the other. It is used to find the product of two values
a=2 b=4 c=a*b print(c)
output:
8
Division Operator
Division operator(/) is used to find the quotient when the first operand is divided by the second.
a=20 b=10 c=a/b print(c)
output:
2.0
Floor Division Operator
Floor division(//) gives the floor value of the quotient when the first operand is divided by the second. In this operator decimal point is not included. For example a=21,b=11 then a//b=1(floor division) a/b=1.9(division).
a=10 b=20 c=a//b print(c)
output:
2
Modulus Operator
The % is the modulus operator. It is used to find the remainder when the first operand is divided by the second. This operator is also called reminder.
a=12 b=4 c=a% b print(c)
output:
0
Exponentiation Operator
Exponentiation operator(**) is used to calculate first operand power to the second operand.
a=5 b=2 c=a**b print(c)
output:
25