Home Course Roadmap
Home Python Foundations Arithmetic Operators
Lesson 10 · Operators

Python Arithmetic Operators

Learn how Python performs mathematical calculations using addition, subtraction, multiplication, division, floor division, modulus, and exponentiation.

30–40 minutes Beginner Python Foundations
Reading Progress 0%
01
Before You Begin

Learning Objectives

By the end of this lesson, you should be able to:

  • Understand the purpose of arithmetic operators in Python.
  • Perform addition, subtraction, multiplication, and division.
  • Understand the difference between / and //.
  • Use the modulus operator to find remainders.
  • Calculate powers using **.
  • Understand operator precedence.
  • Use arithmetic operators with variables and user input.
  • Apply Python arithmetic to real-world problems.
02
Core Concept

What Are Arithmetic Operators?

Arithmetic operators are symbols that tell Python to perform mathematical operations on values.

Python supports all of the common mathematical operations you would expect from a calculator, along with several useful operations specifically designed for programming.

The main arithmetic operators

Python provides +, -, *, /, //, %, and **.

Basic arithmetic
print(10 + 3)
print(10 - 3)
print(10 * 3)
print(10 / 3)
print(10 // 3)
print(10 % 3)
print(2 ** 3)
Output
13
7
30
3.3333333333333335
3
1
8
03
Operator 1

Addition +

The plus sign + is used to add two or more numeric values.

Addition example
first_number = 15
second_number = 8

result = first_number + second_number

print(result)
Output
23

Addition can also be used with floating-point numbers.

Adding decimals
price = 19.99
delivery = 4.50

total = price + delivery

print(total)
04
Operator 2

Subtraction -

The minus sign - subtracts one value from another.

Subtraction example
balance = 500
expense = 175

remaining = balance - expense

print(remaining)
Output
325

Subtraction can produce negative numbers when the second value is larger than the first.

Negative result
result = 10 - 25

print(result)
Output
-15
05
Operator 3

Multiplication *

Python uses the asterisk * for multiplication.

Multiplication example
price = 250
quantity = 4

total = price * quantity

print(total)
Output
1000
Think of multiplication as repetition

If one product costs Rs. 250 and you buy four products, multiplying the price by the quantity gives the total cost.

06
Operator 4

Division /

The forward slash / performs division.

Division example
total = 100
people = 4

share = total / people

print(share)
Output
25.0
Important: division produces a float

Even when the result looks like a whole number, the / operator returns a floating-point value.

Example
result = 10 / 2

print(result)
print(type(result))
Output
5.0
<class 'float'>
07
Operator 5

Floor Division //

Floor division uses two forward slashes: //.

It divides two numbers and returns the result rounded down to the nearest whole number.

Floor division
result = 10 // 3

print(result)
Output
3

Compare this with normal division:

Division vs floor division
print(10 / 3)
print(10 // 3)
Output
3.3333333333333335
3
A deeper point about floor division

Floor division means rounding toward negative infinity, not simply removing the decimal part.

For example, -7 // 3 gives -3.

08
Operator 6

Modulus %

The modulus operator % returns the remainder after division.

Modulus example
result = 10 % 3

print(result)
Output
1

Why is the answer 1?

Three fits into ten three complete times:

Understanding the remainder
3 × 3 = 9
10 - 9 = 1

Therefore, the remainder is 1.

A very useful programming technique

The modulus operator is commonly used to check whether a number is even or odd.

Checking an even number
number = 20

print(number % 2)
Output
0

If a number divided by 2 leaves a remainder of 0, the number is even.

09
Operator 7

Exponentiation **

Python uses two asterisks ** to calculate powers.

Power calculation
result = 2 ** 3

print(result)
Output
8

This means:

Understanding powers
2 ** 3

# Same as:
# 2 × 2 × 2

You can also calculate squares and cubes.

Squares and cubes
number = 5

square = number ** 2
cube = number ** 3

print(square)
print(cube)
Output
25
125
10
Important Concept

Operator Precedence

When an expression contains multiple operators, Python needs to know which operation should be performed first.

This order is called operator precedence.

Python generally follows this order for arithmetic:

  1. Parentheses ()
  2. Exponentiation **
  3. Multiplication, division, floor division, and modulus
  4. Addition and subtraction
Example
result = 2 + 3 * 4

print(result)
Output
14

Python performs multiplication before addition:

Evaluation
2 + 3 * 4

# First:
3 * 4 = 12

# Then:
2 + 12 = 14
Do not rely on guesswork

If an expression is difficult to read, use parentheses to make your intention obvious.

11
Control Evaluation

Using Parentheses

Parentheses allow you to explicitly control which operation Python performs first.

Without parentheses
result = 2 + 3 * 4

print(result)
Output
14
With parentheses
result = (2 + 3) * 4

print(result)
Output
20
Best practice

Use parentheses whenever they improve readability or make the intended order of calculation clearer.

12
Practical Python

Arithmetic with Variables

Arithmetic becomes much more useful when values are stored in variables.

Calculating with variables
length = 12
width = 5

area = length * width

print(area)
Output
60

You can combine several arithmetic operations in a single expression.

Multiple operations
price = 1000
discount = 100
tax = 50

final_price = price - discount + tax

print(final_price)
Output
950
13
Interactive Programs

Arithmetic with User Input

You can combine arithmetic operators with input() to build interactive programs.

Remember that input() returns text, so numeric input should normally be converted before performing calculations.

Simple calculator
first = float(input("Enter first number: "))
second = float(input("Enter second number: "))

total = first + second

print("Total:", total)
Example Output
Enter first number: 25
Enter second number: 15
Total: 40.0
Avoid this mistake

Do not try to perform numeric arithmetic directly on strings returned by input().

Correct approach
age = int(input("Enter your age: "))

next_year = age + 1

print("Next year:", next_year)
14
Real-World Applications

Arithmetic in Real-World Programs

Shopping Bill

Arithmetic operators can calculate the total price of products.

Shopping calculation
item_price = 1200
quantity = 3

subtotal = item_price * quantity

print("Subtotal:", subtotal)
Output
Subtotal: 3600

Rectangle Area

Area calculation
length = 20
width = 8

area = length * width

print("Area:", area)
Output
Area: 160

Average of Numbers

Average calculation
math_marks = 80
english_marks = 75
computer_marks = 90

total = math_marks + english_marks + computer_marks

average = total / 3

print("Total:", total)
print("Average:", average)
Output
Total: 245
Average: 81.66666666666667
15
Troubleshooting

Common Mistakes

1. Using the wrong division operator

Remember the difference:

Important distinction
print(7 / 2)
print(7 // 2)
Output
3.5
3

2. Forgetting operator precedence

This:

Expression
result = 10 + 5 * 2

produces 20, not 30, because multiplication happens first.

3. Forgetting to convert input

Input values are strings by default.

Correct approach
number = int(input("Enter a number: "))

result = number * 2

print(result)

4. Dividing by zero

Python cannot divide a number by zero.

Invalid calculation
result = 10 / 0
ZeroDivisionError

Attempting to divide by zero raises a ZeroDivisionError.

16
Practice

Practice Exercises

Try these exercises yourself before looking at other solutions.

Exercise 1 — Basic Arithmetic

Create a program that calculates:

  • 25 + 15
  • 50 - 17
  • 8 × 6
  • 100 ÷ 4

Exercise 2 — Remainder

Use the modulus operator to find the remainder when 47 is divided by 5.

Exercise 3 — Square

Store the number 12 in a variable and calculate its square using **.

Exercise 4 — Rectangle

Store the length and width of a rectangle in variables and calculate its area.

Exercise 5 — Shopping

A product costs Rs. 750 and a customer buys 4 units. Calculate the total price.

Exercise 6 — User Input

Ask the user for two numbers and display their sum, difference, product, and division result.

17
Build Something

Mini Challenge — Simple Bill Calculator

Build a small Python program that asks the user for the price of a product and the quantity purchased.

Your program should calculate:

  • Subtotal
  • 10% discount
  • Final price after discount
Challenge requirements

Use input(), float(), multiplication, subtraction, and division or percentage arithmetic.

One possible solution
price = float(input("Enter product price: "))
quantity = int(input("Enter quantity: "))

subtotal = price * quantity
discount = subtotal * 0.10
final_price = subtotal - discount

print("Subtotal:", subtotal)
print("Discount:", discount)
print("Final price:", final_price)
Challenge extension

Add a tax calculation after the discount and display the final amount the customer has to pay.

18
Test Yourself

Quick Knowledge Check

1. Which operator is used for multiplication?

2. What is the result of 10 // 3?

3. Which operator returns the remainder?

4. What is the result of 2 ** 4?

5. What is the result of 2 + 3 * 4?

6. What does / normally return?

7. Which operation should you use to calculate the square of 7?

19
Wrap Up

Lesson Summary

Arithmetic operators are fundamental building blocks of Python programming. They allow programs to perform calculations, process data, and solve real-world problems.

Operator Purpose Example
+ Addition 10 + 3
- Subtraction 10 - 3
* Multiplication 10 * 3
/ Division 10 / 3
// Floor division 10 // 3
% Remainder 10 % 3
** Exponentiation 2 ** 3
Key takeaway

Learn the operators, understand their behavior, and then practice combining them with variables and user input. This is the foundation for building useful Python programs.

Ready to continue?

Complete this lesson once you have practiced the arithmetic operators and understand how Python evaluates expressions.