Skip to main content

Arithmetic Operators

Arithmetic operators handle common math on numbers:

Arithmetic Operators Table

main.py
# + Addition        x + y
# - Subtraction     x - y
# * Multiplication  x * y
# / Division        x / y
# % Modulus         x % y
# ** Exponentiation x ** y
# // Floor division x // y

Examples

This example runs them all on two numbers:

Example

Prompt
Write a Python program that assigns x = 15 and y = 4, then prints the result of addition, subtraction, multiplication, division, modulus, exponentiation, and floor division.
Output: complete Python program

Division in Python

Python gives you two ways to divide:

  • / - Division, which gives a float
  • // - Floor division, which gives an integer for two integers

Example

The / operator always gives you a float:

Prompt
Write a Python program that assigns x = 12 and y = 5, then prints x / y to show that division always returns a float.
Output: complete Python program

Example

Floor division rounds DOWN to a whole number, so two integers give an integer:

Prompt
Write a Python program that assigns x = 12 and y = 5, then prints x // y to show floor division rounds down to the nearest integer.
Output: complete Python program