Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 02

Arithmetic Operators

Perform addition, subtraction, multiplication, true division, floor division, modulo, and exponentiation in Python.

Beginner18 min

Arithmetic operators perform mathematical operations such as addition, subtraction, multiplication, and division.

When values, variables, or objects are connected using arithmetic operators, the result is an arithmetic expression.

python
a = 10
b = 3

print(a + b)
text
13

Visual reference

10 plus 3 equals 13 — an arithmetic expression

10 + 3 becomes the arithmetic expression 13.

What you'll learn

  • The seven arithmetic operators
  • Why / always returns a float quotient
  • How // behaves with integers and floats
  • Finding square roots using ** 0.5

The seven arithmetic operators

Symbol Meaning Example Result
+ Addition 10 + 3 13
- Subtraction 10 - 3 7
* Multiplication 10 * 3 30
/ True division 10 / 3 3.333…
// Floor division 10 // 3 3
% Modulo 10 % 3 1
** Exponentiation 10 ** 3 1000

Interactive playground

Interactive playground

Adjust the values and see every arithmetic operator update instantly.

  • Addition

    13

    10 + 3

  • Subtraction

    7

    10 - 3

  • Multiplication

    30

    10 * 3

  • True division

    3.333333

    10 / 3

  • Floor division

    3

    10 // 3

  • Modulo

    1

    10 % 3

  • Exponentiation

    1000

    10 ** 3

Equivalent Python code

a, b = 10, 3

print("sum", a + b)
print("sub", a - b)
print("mul", a * b)
print("div", a / b)
print("floor", a // b)
print("mod", a % b)
print("pow", a ** b)

Square root using `** 0.5`

16 ** 0.5

4

Understanding / vs //

True division (/)

python
print(10 / 3)
text
3.3333333333333335

Floor division (//)

python
print(10 // 3)
text
3

The // operator removes the fractional part by taking the floor of the result.

What happens when floats are involved?

Even with //, if either operand is a float, the result is still a float type.

Expression Result Type
10 / 3 3.3333333333333335 float
10 // 3 3 int
10.0 // 3.0 3.0 float
10 // 3.0 3.0 float
python
print(10.0 / 3.0)
print(10.0 // 3.0)
print(10.0 / 3)
print(10.0 // 3)
print(10 / 3.0)
print(10 // 3.0)
text
3.3333333333333335
3.0
3.3333333333333335
3.0
3.3333333333333335
3.0

Exponentiation (**)

The ** operator raises a number to a power.

python
print(10 ** 3)
print(2 ** 5)
text
1000
32

Read 10 ** 3 as “10 to the power of 3.”

Square root using ** 0.5

python
n = 16
print(n ** 0.5)
text
4.0

Use the interactive block above to try other values, or run 81 ** 0.5 in the playground.

Interactive program (two numbers)

This version uses input() to read values from the keyboard.

python
a = int(input("Enter value of a: "))
b = int(input("Enter value of b: "))

print("sum({}, {}) = {}".format(a, b, a + b))
print("div({}, {}) = {}".format(a, b, a / b))
print("floor_div({}, {}) = {}".format(a, b, a // b))
print("pow({}, {}) = {}".format(a, b, a ** b))

Example input: 10 and 3.

Practice exercises

  1. Predict the output of 10 // 3 and 10 / 3 before running.
  2. Predict the result of 10.0 // 3.
  3. Print the square root of 81 using 81 ** 0.5.

Quick knowledge check

  1. What does / return?
    A float quotient.

  2. What is 10 // 3?
    3

  3. What is 10.0 // 3?
    3.0

Summary

  • Python has seven arithmetic operators: +, -, *, /, //, %, **.
  • / always performs true division and returns a float.
  • // performs floor division; with floats, the result remains a float.
  • ** is used for powers; ** 0.5 gives a compact square root.

Next lesson: Assignment Operator — =, multi-target assignment, and swapping variables.

Loading playground…