After completing this chapter, you will be able to:
- Understand Arithmetic Operators.
- Explain why arithmetic operators are used.
- Learn all arithmetic operators in Python.
- Perform mathematical calculations.
- Write programs using arithmetic operators.
- Understand operator precedence in arithmetic expressions.
Arithmetic operators are one of the most frequently used operators in Python.
They are used to perform mathematical calculations on numbers.
Examples include:
- Addition
- Subtraction
- Multiplication
- Division
- Finding the remainder
- Calculating powers
- Floor division
Arithmetic operators are widely used in banking applications, billing software, scientific calculations, payroll systems, and engineering applications.
Arithmetic Operators are special symbols used to perform mathematical operations on numeric values.
Example
a = 20
b = 10
print(a + b)Output
30
Here,
+is the arithmetic operator.20and10are operands.
Arithmetic operators are used to:
- Perform mathematical calculations.
- Calculate totals.
- Find averages.
- Calculate discounts.
- Compute salaries.
- Perform scientific calculations.
| Operator | Name | Example |
|---|---|---|
| + | Addition | a + b |
| - | Subtraction | a - b |
| * | Multiplication | a * b |
| / | Division | a / b |
| // | Floor Division | a // b |
| % | Modulus | a % b |
| ** | Exponent | a ** b |
The Addition operator adds two operands.
a = 25
b = 15
print("Addition :", a + b)Addition : 40
The Subtraction operator subtracts one operand from another.
a = 25
b = 15
print("Subtraction :", a - b)Subtraction : 10
The Multiplication operator multiplies two operands.
a = 25
b = 15
print("Multiplication :", a * b)Multiplication : 375
The Division operator divides one operand by another and always returns a float value.
a = 25
b = 5
print("Division :", a / b)Division : 5.0
The Floor Division operator returns the quotient without the decimal part.
a = 25
b = 4
print("Floor Division :", a // b)Floor Division : 6
The Modulus operator returns the remainder after division.
a = 25
b = 4
print("Remainder :", a % b)Remainder : 1
The Exponent operator calculates the power of a number.
a = 5
print("Square :", a ** 2)
print("Cube :", a ** 3)Square : 25
Cube : 125
Write a Python program to perform all arithmetic operations on two numbers.
# Store two numbers
a = 20
b = 6
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)Addition : 26
Subtraction : 14
Multiplication : 120
Division : 3.3333333333333335
Floor Division : 3
Modulus : 2
Exponent : 64000000
START
Create two variables
Perform all arithmetic operations
Display the results
STOP
a = 20
b = 6Stores two integer values.
Each print() statement performs one arithmetic operation and displays the result.
Arithmetic operators follow the following precedence.
()
**
*, /, //, %
+, -
Example
result = 10 + 5 * 2
print(result)Output
20
Explanation
Multiplication is performed before addition.
Arithmetic operators are used in:
- Banking Applications
- Payroll Systems
- Billing Software
- Shopping Applications
- Student Result Processing
- Scientific Calculations
- Engineering Software
- Easy mathematical calculations.
- Reduces coding effort.
- Improves readability.
- Supports complex calculations.
print(10 / 3)Output
3.3333333333333335
print(10 // 3)Output
3
print(10 / 0)Output
ZeroDivisionError
Arithmetic operators perform mathematical operations on numeric values.
The Modulus operator (%).
/returns the actual division result (float).//returns the floor division result (integer quotient).
The Exponent operator (**).
Python raises a ZeroDivisionError.
+→ Addition-→ Subtraction*→ Multiplication/→ Division//→ Floor Division%→ Modulus**→ Exponent
In this chapter, you learned:
- What Arithmetic Operators are.
- Types of Arithmetic Operators.
- Syntax and examples.
- Practical programs.
- Operator precedence.
- Real-world applications.
- Common mistakes.
- Interview questions.