Arithmetic Operators in Python
Arithmetic operators in python are used to perform mathematical calculations between two operands.
Symbol | Operation | Example |
---|---|---|
+ | Addition | x + y |
– | Subtraction | x – y |
* | Multiplication | x * y |
/ | Division | x / y |
% | Modulus | x % y |
** | Exponent | x ** y |
// | Floor Division | x // y |
Let’s understand each operator one by one with the help of examples:
“+” Operator in Python
+ Operator in Python is use to perform addition between two operands or values.
Example of Arithmetic + operator in Python
# Program in Python to add two numbers using + operator
a = 10
b = 5
c = a + b
print(c)
Output:
15
“-” Operator
“-” Operator in Python is use to perform subtraction between two operands or values.
Example of Arithmetic “-” operator in Python
# Program in Python to subtract two numbers using "-" operator
a = 10
b = 5
c = a - b
print(c)
Output:
5
“*” Operator in Python
* Operator in Python is use to perform multiplication between two operands or values.
Example of Multiplication “*” operator in Python
# Program in Python to multiply two numbers using * operator
a = 10
b = 5
c = a * b
print(c)
Output:
50
“/” Operator in Python
/ Operator in Python is use to perform division operation between two operands or values.
Example of Division “/” operator in Python
# Program in Python to divide two numbers using / operator
a = 10
b = 5
c = a / b
print(c)
Output:
2
“%” Operator in Python
% Operator in Python is use to get modulus of two operands or values.
Example of Modulus % operator in Python
# Program in Python to find mod of numbers using % operator
a = 10
b = 5
c = a % b
print(c)
Output:
0
“**” Operator in Python
** Operator in Python is use to raise power.
Example of Exponent ** operator in Python
# Program in Python to calculate the power of number using ** operator
a = 10
b = 2
c = a ** b
print(c)
Output:
100
“//” Operator in Python
// Operator in Python is use to perform division operation and get the result in round figures.
Example of Floor Division // operator in Python
# Program in Python to calculate the floor division of number using // operator
a = 11
b = 2
c = a // b
print(c)
Output:
5
[…] Arithmetic operators […]
Thanks!
–