Arithmetic operators are used for mathematical computations. Arithmetic operators are used with numeric values like integers or float.
Following are the Arithmetic operators in python:
- + (Addition) operator
- – (Subtraction) operator
- * (Multiplication) operator
- / (Division) operator
- // (Floor Division) operator
- % (Modulus) operator
- ** (Exponent) operator
+ operator:
+ is an addition operator. This operator is used to add two numbers.
Example:
num1 = 10
num2 = 20
total = num1 + num2
print(total)
Output:
30
– operator:
-is a subtraction operator. This operator is used for subtracting two numbers.
Example:
num1 = 10
num2 = 20
total = num2 - num1
print(total)
Output:
10
* operator:
* is the multiplication operator. * operator is used for multiplication.
Example:
num1 = 10
num2 = 20
total = num1 * num2
print(total)
Output:
200
/ operator:
/ is a division operator. / is used for division. It returns result in float.
Example:
num1 = 10
num2 = 20
total = num2 / num1
print(total)
Output:
2.0
// operator:
// is a floor division operator. // is used for division. But this operator returns result in an integer.
Example:
num1 = 10
num2 = 3
total = num1 // num2
print(total)
Output:
3
% operator:
% is a modulus operator. % is a modulus operator which gives the remainder of the division.
Example:
num1 = 10
num2 = 3
total = num1 % num2
print(total)
Output:
1
** operator:
** is an exponent operator.
Example:
num1 = 10
num2 = 3
total = num1 ** num2
print(total)
Output:
1000
Conclusion:
From this article, you learned different arithmetic operators in python with examples. If you have problems while implementing code, you can ask me through the comment section.