Lessons
Courses

Arithmetic Operators in Python [ English ]

1. Introduction

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).

2. Types of Arithmetic Operators

OperatorNameDescriptionExample
+AdditionAdds two values5 + 3 = 8
-SubtractionSubtracts one value from another5 - 3 = 2
*MultiplicationMultiplies two values5 * 3 = 15
/DivisionDivides and returns float5 / 2 = 2.5
//Floor DivisionDivides and returns integer part5 // 2 = 2
%ModulusReturns remainder5 % 2 = 1
**ExponentRaises power2 ** 3 = 8

3. Detailed Explanation of Each Operator


3.1 Addition (+)

Adds two numbers.

a = 10b = 5print(a + b)

Output

15

3.2 Subtraction (-)

Subtracts one number from another.

print(10 - 5)

Output

5

3.3 Multiplication (*)

Multiplies two numbers.

print(4 * 3)

Output

12

3.4 Division (/)

Performs division and always returns a float value.

print(5 / 2)

Output

2.5

3.5 Floor Division (//)

Returns the integer part (quotient) of division.

print(5 // 2)

Output

2

3.6 Modulus (%)

Returns the remainder of division.

print(5 % 2)

Output

1

3.7 Exponent (**)

Raises one number to the power of another.

print(2 ** 3)

Output

8

4. Arithmetic Operators with Different Data Types

a = 5 # intb = 2.5 # float print(a + b)

Output

7.5

Explanation

  • Python automatically converts int to float (implicit type casting)

5. Special Behavior of Operators

5.1 Division Always Returns Float

print(6 / 3)

Output:

2.0

5.2 Modulus with Negative Numbers

print(-5 % 2)

Output:

1

5.3 Exponent with Negative Power

print(2 ** -2)

Output:

0.25

6. Operator Precedence in Arithmetic

Order of execution:

  1. ** (Exponent)
  2. *, /, //, %
  3. +, -

Example

result = 2 + 3 * 4print(result)

Output

14

7. Practical Example

a = 10b = 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)

8. Summary

  • 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.