Arithmetic operators in Python are used to perform mathematical calculations such as addition, subtraction, multiplication, and division. These operators work with numeric data types like integers (int) and floating-point numbers (float).
| Operator | Name | Description | Example |
|---|---|---|---|
+ |
Addition | Adds two values | 5 + 3 = 8 |
- |
Subtraction | Subtracts one value from another | 5 - 3 = 2 |
* |
Multiplication | Multiplies two values | 5 * 3 = 15 |
/ |
Division | Divides and returns float | 5 / 2 = 2.5 |
// |
Floor Division | Divides and returns integer part | 5 // 2 = 2 |
% |
Modulus | Returns remainder | 5 % 2 = 1 |
** |
Exponent | Raises power | 2 ** 3 = 8 |
+)Adds two numbers.
a = 10
b = 5
print(a + b)
Output
15
-)Subtracts one number from another.
print(10 - 5)
Output
5
*)Multiplies two numbers.
print(4 * 3)
Output
12
/)Performs division and always returns a float value.
print(5 / 2)
Output
2.5
//)Returns the integer part (quotient) of division.
print(5 // 2)
Output
2
%)Returns the remainder of division.
print(5 % 2)
Output
1
**)Raises one number to the power of another.
print(2 ** 3)
Output
8
a = 5 # int
b = 2.5 # float
print(a + b)
Output
7.5
Explanation
int to float (implicit type casting)print(6 / 3)
Output:
2.0
print(-5 % 2)
Output:
1
print(2 ** -2)
Output:
0.25
Order of execution:
** (Exponent)*, /, //, %+, -result = 2 + 3 * 4
print(result)
Output
14
a = 10
b = 3
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Floor Division:", a // b)
print("Modulus:", a % b)
print("Exponent:", a ** b)
Arithmetic operators are used for mathematical calculations.
Types include:
+, -, *, /, //, %, **Division (/) always returns a float.
Floor division (//) returns integer result.
Modulus (%) gives the remainder.
Exponent (**) is used for power calculations.
Operator precedence determines execution order.