Arithmetic operations are among the most fundamental tasks in programming. Whether you are calculating a student’s average marks, determining monthly sales, computing profit margins, analyzing customer spending, or building Machine Learning algorithms, arithmetic operators are used extensively. Every Python programmer must understand how these operators work because they form the foundation for mathematical calculations and data processing.
Python provides a rich set of arithmetic operators that allow you to perform mathematical operations quickly and efficiently. These operators work with integers, floating-point numbers, complex numbers, and other numeric data types. Understanding when and how to use each operator is essential for writing accurate and efficient programs.
In Data Analytics, arithmetic operators are used almost everywhere. Analysts calculate averages, percentages, growth rates, discounts, taxes, standard deviations, and many other business metrics using these operators. Similarly, Machine Learning algorithms rely heavily on arithmetic calculations for model training, optimization, and prediction.
In this lesson, you will learn every Python arithmetic operator in detail with practical coding examples, real-world business scenarios, and Data Analytics applications. By the end of this lesson, you will be able to confidently perform mathematical calculations using Python.
After completing this lesson, you will be able to:
Arithmetic operators are special symbols used to perform mathematical operations on numeric values. They take one or more operands (numbers or variables) and produce a new value as the result of the calculation.
For example, if you want to add two numbers together, Python uses the + operator. Similarly, subtraction uses -, multiplication uses *, and division uses /.
Consider the following expression:
a = 15
b = 5
result = a + b
print(result)
Output:
20
In this example:
a is the first operand.b is the second operand.+ is the arithmetic operator.20 is the result of the operation.Arithmetic operators make mathematical computations simple and readable. Instead of writing lengthy calculations manually, Python performs them efficiently using these built-in operators.
Arithmetic operators are used in almost every Python application. From basic calculators to advanced Artificial Intelligence systems, mathematical operations are unavoidable. Every software application that works with numbers depends on arithmetic operators.
Some common applications include:
For example, suppose a retail company wants to calculate the total bill for a customer.
price = 499
quantity = 3
total = price * quantity
print(total)
Output:
1497
Without arithmetic operators, performing such calculations programmatically would not be possible.
Python provides the following arithmetic operators:
| Operator | Name | Example | Result |
|---|---|---|---|
| + | Addition | 10 + 5 | 15 |
| – | Subtraction | 10 – 5 | 5 |
| * | Multiplication | 10 * 5 | 50 |
| / | Division | 10 / 5 | 2.0 |
| // | Floor Division | 10 // 3 | 3 |
| % | Modulus | 10 % 3 | 1 |
| ** | Exponentiation | 2 ** 3 | 8 |
In this first chunk, we will focus on the two most commonly used arithmetic operators: Addition (+) and Subtraction (-).
The + operator is used to add two or more numeric values. It is one of the most frequently used operators in Python and is commonly used in business calculations, statistics, finance, and Data Analytics.
result = operand1 + operand2
a = 25
b = 15
print(a + b)
Output:
40
english = 85
maths = 91
science = 88
total_marks = english + maths + science
print(total_marks)
Output:
264
price = 199.99
tax = 36.00
total = price + tax
print(total)
Output:
235.99
Suppose a company records sales for three consecutive months.
january = 125000
february = 143500
march = 162800
quarter_sales = january + february + march
print(quarter_sales)
Output:
431300
This calculation helps analysts determine quarterly revenue.
The - operator subtracts one numeric value from another. It is widely used to calculate differences, remaining balances, losses, discounts, and changes between two values.
result = operand1 - operand2
a = 45
b = 18
print(a - b)
Output:
27
balance = 25000
withdraw = 4500
remaining = balance - withdraw
print(remaining)
Output:
20500
total_marks = 500
obtained = 438
remaining = total_marks - obtained
print(remaining)
Output:
62
Suppose a business wants to calculate monthly profit.
revenue = 250000
expenses = 172000
profit = revenue - expenses
print(profit)
Output:
78000
This type of calculation is performed frequently in financial dashboards and business intelligence reports.
In this section, you learned the fundamentals of Python arithmetic operators and explored why they are essential in programming, Data Analytics, and Machine Learning. You studied the Addition (+) and Subtraction (-) operators, their syntax, practical coding examples, and real-world business applications. In the next chunk, you will learn the remaining arithmetic operators: Multiplication (*), Division (/), Floor Division (//), Modulus (%), and Exponentiation (**), along with practical examples and common use cases.
The multiplication operator (*) is used to multiply two or more numeric values. It is one of the most frequently used operators in mathematics, finance, engineering, Data Analytics, and Machine Learning.
Whenever you need to calculate totals, revenue, area, salary, commission, inventory value, or repeated quantities, the multiplication operator is commonly used.
result = operand1 * operand2
a = 15
b = 8
print(a * b)
Output:
120
price = 19.99
quantity = 6
total = price * quantity
print(total)
Output:
119.94
length = 25
width = 12
area = length * width
print(area)
Output:
300
Suppose a company sells 450 products, each priced at $125.
price = 125
quantity = 450
revenue = price * quantity
print(revenue)
Output:
56250
Revenue calculation is one of the most common uses of multiplication in business analytics.
Python also allows the multiplication operator to repeat a string multiple times.
print("Python " * 3)
Output:
Python Python Python
This feature is useful for creating repeated patterns, separators, or formatted output.
The division operator (/) divides one number by another. Unlike some programming languages, Python always returns a floating-point value when using the standard division operator, even if the result is mathematically a whole number.
result = operand1 / operand2
a = 20
b = 5
print(a / b)
Output:
4.0
print(10 / 3)
Output:
3.3333333333333335
Python preserves precision instead of automatically rounding the result.
total_marks = 438
subjects = 5
average = total_marks / subjects
print(average)
Output:
87.6
Calculating averages is one of the most common tasks in analytics.
sales = 1250000
months = 12
average_monthly_sales = sales / months
print(average_monthly_sales)
This helps businesses evaluate monthly performance.
Attempting to divide a number by zero raises an exception.
print(10 / 0)
Output:
ZeroDivisionError
Always validate the denominator before performing division.
The floor division operator (//) divides two numbers and returns only the integer portion of the result by removing the decimal part.
Instead of rounding the value, Python rounds down toward negative infinity.
result = operand1 // operand2
print(10 // 3)
Output:
3
print(25 // 4)
Output:
6
| Expression | Operator | Result |
|---|---|---|
| 10 / 3 | / | 3.3333333333333335 |
| 10 // 3 | // | 3 |
Suppose 125 students need to be seated in classrooms that can each accommodate 30 students.
students = 125
capacity = 30
full_rooms = students // capacity
print(full_rooms)
Output:
4
This indicates that four classrooms can be completely filled.
The modulus operator (%) returns the remainder after division.
It is commonly used to determine whether a number is even or odd, cycle through values, validate intervals, and perform scheduling tasks.
result = operand1 % operand2
print(10 % 3)
Output:
1
print(20 % 5)
Output:
0
number = 18
if number % 2 == 0:
print("Even")
else:
print("Odd")
Output:
Even
Suppose customer IDs ending in an even number receive a promotional discount.
customer_id = 1042
if customer_id % 2 == 0:
print("Eligible")
else:
print("Not Eligible")
The exponentiation operator (**) raises a number to the power of another number.
This operator is widely used in mathematics, statistics, scientific computing, and Machine Learning.
result = base ** exponent
print(2 ** 3)
Output:
8
print(5 ** 2)
Output:
25
A square root can be calculated using an exponent of 0.5.
number = 64
print(number ** 0.5)
Output:
8.0
Distance calculations, variance, standard deviation, and many optimization algorithms frequently use exponentiation.
x = 6
square = x ** 2
cube = x ** 3
print(square)
print(cube)
Output:
36
216
| Operator | Name | Example | Output |
|---|---|---|---|
| + | Addition | 15 + 5 | 20 |
| – | Subtraction | 15 – 5 | 10 |
| * | Multiplication | 15 * 5 | 75 |
| / | Division | 15 / 5 | 3.0 |
| // | Floor Division | 15 // 4 | 3 |
| % | Modulus | 15 % 4 | 3 |
| ** | Exponentiation | 2 ** 5 | 32 |
In this section, you explored the remaining arithmetic operators in Python: Multiplication (*), Division (/), Floor Division (//), Modulus (%), and Exponentiation (**). You learned their syntax, practical coding examples, business applications, and Data Analytics use cases. In the next chunk, you will study operator precedence, order of evaluation, complex arithmetic expressions, real-world analytics examples, common mistakes, and best practices for writing efficient mathematical expressions in Python.
When an arithmetic expression contains multiple operators, Python follows a predefined order to decide which operation should be performed first. This order is known as operator precedence.
Understanding operator precedence is essential because the same expression can produce different results depending on the order in which operations are executed.
Consider the following example:
result = 10 + 5 * 2
print(result)
Output:
20
Many beginners expect the answer to be 30. However, Python first performs multiplication because multiplication has a higher precedence than addition.
The calculation is performed as follows:
10 + (5 * 2)
10 + 10
20
Python evaluates arithmetic operators according to the following order.
| Priority | Operator | Description |
|---|---|---|
| 1 | () | Parentheses |
| 2 | ** | Exponentiation |
| 3 | *, /, //, % | Multiplication, Division, Floor Division, Modulus |
| 4 | +, – | Addition and Subtraction |
Whenever multiple operators have the same precedence level, Python evaluates them from left to right (except exponentiation, which is evaluated from right to left).
Parentheses allow you to control the order of execution explicitly. Expressions inside parentheses are always evaluated first.
result = (10 + 5) * 2
print(result)
Output:
30
Python first evaluates:
(10 + 5)
15 × 2
30
Using parentheses makes code easier to understand and reduces the chance of logical errors.
print(5 + 4 * 3)
Output:
17
Evaluation:
4 × 3 = 12
5 + 12 = 17
print((5 + 4) * 3)
Output:
27
print(20 - 8 / 2)
Output:
16.0
Python first performs division.
8 / 2 = 4
20 - 4 = 16
print((20 - 8) / 2)
Output:
6.0
print(2 ** 3 * 5)
Output:
40
Python first calculates:
2 ** 3 = 8
8 × 5 = 40
Operators having the same precedence level are evaluated from left to right.
print(24 / 4 * 2)
Output:
12.0
Evaluation:
24 / 4 = 6
6 × 2 = 12
The exponentiation operator (**) is evaluated from right to left.
print(2 ** 3 ** 2)
Output:
512
Python evaluates:
3 ** 2 = 9
2 ** 9 = 512
It is not evaluated as:
(2 ** 3) ** 2
price = 120
quantity = 15
tax = 250
bill = price * quantity + tax
print(bill)
Output:
2050
Multiplication occurs before addition.
obtained = 438
total = 500
percentage = (obtained / total) * 100
print(percentage)
Output:
87.6
Parentheses improve readability and ensure the intended calculation is performed first.
radius = 7
area = 3.14159 * radius ** 2
print(area)
Python first calculates the exponent and then performs multiplication.
Arithmetic operators are used extensively in Data Analytics to derive business insights from raw data.
total_revenue = 960000
months = 12
average = total_revenue / months
print(average)
previous = 125000
current = 158000
growth = ((current - previous) / previous) * 100
print(growth)
This formula is widely used in financial reporting and business intelligence dashboards.
profit = 85000
sales = 350000
margin = (profit / sales) * 100
print(margin)
Such calculations are common in Power BI, Tableau, Excel, and Python analytics projects.
sales = 250000
customers = 1250
average_spend = sales / customers
print(average_spend)
This metric helps businesses understand customer purchasing behavior.
// instead of / when a decimal result is required.%) with percentage calculations.^ instead of ** for exponentiation.ZeroDivisionError.Predict the output before running each program.
print(15 + 5 * 2)
print((15 + 5) * 2)
print(25 % 4)
print(5 ** 3)
print(30 // 7)
In this section, you learned how Python evaluates arithmetic expressions using operator precedence and associativity. You explored the precedence order of arithmetic operators, the role of parentheses, left-to-right and right-to-left evaluation, and practical examples from business and Data Analytics. You also reviewed common mistakes and best practices for writing accurate and readable mathematical expressions. In the final chunk, you will complete this lesson with a summary, key takeaways, FAQs, MCQs, coding exercises, interview questions, a mini project, and a preview of the next lesson on Python Assignment Operators.
In this lesson, you learned about Python arithmetic operators, which are the foundation of mathematical programming. You explored how Python performs addition, subtraction, multiplication, division, floor division, modulus, and exponentiation. You also learned how Python evaluates arithmetic expressions using operator precedence and associativity.
Throughout the lesson, you worked with practical coding examples, business scenarios, and Data Analytics applications. These operators are used daily in software development, financial analysis, scientific computing, data processing, Machine Learning, and Artificial Intelligence.
Understanding arithmetic operators is essential because almost every Python program performs some form of calculation. Whether you are building a calculator, analyzing sales data, creating dashboards, or developing predictive models, arithmetic operators will be among the most frequently used tools in your code.
+, -, *, /, //, %, and **./) always returns a floating-point result.//) returns the integer quotient by discarding the fractional part.%) returns the remainder after division.**) raises a number to the power of another.Arithmetic operators are symbols used to perform mathematical operations such as addition, subtraction, multiplication, division, modulus, floor division, and exponentiation.
Python provides seven arithmetic operators: +, -, *, /, //, %, and **.
/ and //?
The / operator performs normal division and returns a floating-point value, whereas // performs floor division and returns the integer quotient after removing the fractional part.
The modulus operator (%) returns the remainder after division and is commonly used to determine whether a number is even or odd.
Exponentiation uses the ** operator. For example, 2 ** 4 returns 16.
Parentheses override the default operator precedence and make complex expressions easier to understand.
All arithmetic operators are important, but addition, subtraction, multiplication, and division are the most commonly used.
Yes. Python arithmetic operators support integers, floating-point numbers, and complex numbers.
Python raises a ZeroDivisionError.
They are used in finance, accounting, engineering, statistics, Data Analytics, Machine Learning, Artificial Intelligence, scientific computing, and software development.
/) and floor division (//).** instead of ^?Create a Python program named student_result.py that performs the following tasks:
Challenge: Extend the program to assign grades (A, B, C, D, or F) based on the calculated percentage.
Congratulations! You have completed the lesson on Python Arithmetic Operators. You now understand how to perform mathematical calculations, evaluate expressions using operator precedence, and apply arithmetic operators in real-world programming and Data Analytics scenarios.
In the next lesson, you will learn Python Assignment Operators. You will explore simple assignment, compound assignment operators such as +=, -=, *=, /=, //=, %=, and **=, along with practical coding examples and best practices.