Python Arithmetic Operators

Python Arithmetic Operators

Now, we are going to learn about the arithmetic operators in python. As the name suggests, arithmetic operators are the operators which are used with numbers (numerical values) to perform different mathematical operations like Addition, Subtraction, Multiplication, Division, etc… So, here are some of the arithmetic operators symbols, with their descriptions and an example to easily understand the concept.

OperatorDescriptionExample
+This operator is used for addition.If a = 3 and b = 5, then a + b = 8
This operator is used for subtraction.If a = 6 and b = 4, then a – b = 2
*This operator is used for multiplication.If a = 5 and b = 7, then a*b = 35
/This operator is used for division.If a = 15 and b = 2, then a/b = 7.5
//This operator is used for floor division.If a = 15 and b = 2, then a//b= 7
%This operator is a modulus operator, used to get the remainder after division.If a = 10 and b = 2, then a%b=0
(As 2 divides 10)
**This operator is an exponentiation operator, and we can calculate left operand to the power of right operand.If a = 2 and b = 3, then a**b=8
(It is like a to the power of b)

Now, let’s have a look at a simple program, to have a look at these different arithmetic operators, which help us do some different arithmetic operations, like addition, subtraction, multiplication, division, etc..

As you can see, in the above program, we are taking two user input numbers, and then we are trying to perform some different arithmetic operations, like addition, subtraction, multiplication, division, etc.. Let’s have a look at the output of the above program –

Please enter the first number: 12
Please enter the second number: 2
Addition: 14
subtraction: 10
multiplication: 24
division: 6.0
floor division: 6
exponentiation: 144
Modulus: 0

As you can see, we have the outputs for the respective operations. These are some very regular operations, which we can simply understand, and implement very easily, as and when required. Now, let’s move on to understanding the other operators.