Python Arithmetic Operators

Arithmetic operators are used to manipulate mathematical expressions.

Python Arithmetic Operators are listed below :-

+ Addition Return Sum of two operands
- Subtraction Return difference between two operands
* Multiplication Return product of two operands
% Modulus Return remainder value of division
/ Division Return quotient value of division
// Floor Division Return quotient value in form of real number(it ignores decimal part )
** Exponentiation Return exponent of first operand raised to the power of second number

Let’s  understand each arithmetic operator in detail through a program :-

Program using Addition (+)

x = 10     
y = 20
z = x + y
print(z)

The binary plus (+) operator is used to perform addition of two numbers. So, the above expression will be z=10+20, and the output will be :-

30

Program using Subtraction (-)

x = 20
y = 5
z = x - y // x = 20, y = 5
print(z)

The binary minus (-) operator is used to perform subtraction between two numbers. So, the expression will be z = 20 - 5, and the output will be :-

15

Program using Multiplication (*)

x = 3
y = 4
z = x * y
print(z)

The multiplication operator is used to get the product of two numbers. So, the expression will be z = 3 * 4, and the output will be :-

12

 Program using Division (/)

x = 15
y = 2
z = x / y
print(z)

The division operator is used to get a quotient of division between two numbers. So the expression will be z = 15 / 2, and the output will be :-

7.5

Program using Floor Division (//)

x = 15
y = 2
z = x // y
print(z)

The floor division operator is used to get a quotient value  without a decimal point. The floor operator performs division between two numbers and the results of the division are converted into the whole number by adjusting the number to the left in the number line.

So, the expression will be z = 15 // 2, and the output will be :-

7

Program using Modulus (%)

x = 12
y = 5
z = x % y
print(z)

The modulus operator also performs division between two numbers, but it returns the remainder value of division, when the left operand is divided by the right one. So, the expression will be z = 12 / 5, and the output will be :-

2

Program using Expo (**)

x = 3
y = 2
z = x ** y
print(z)

This ** operator is called exponent operator and it is used to get the power of a number. The operator raised the power of the left operand. So, the expression will be z = 3 ** 2 or z = 3 * 3, and the output will be :-

9

Note : All the arithmetic operators are binary operators.