Skip to content

Python Arithmetic Operators

Syntax

Arithmetic operators in Python are used to perform basic mathematical operations like addition, subtraction, multiplication, division, and more.

+ # Adds
- # Subtracts
* # Multiplies
/ # Divides (returns float)
// # Divides (returns int)
% # Remainder
** # Exponent
addition = x + y # Adds x and y
subtraction = x - y # Subtracts y from x
multiplication = x * y # Multiplies x and y
division = x / y # Divides x by y (returns float)
floor_division = x // y # Divides x by y (returns int)
modulus = x % y # Remainder of x divided by y
exponent = x ** y # x raised to the power of y

Example

# Calculating the results of different operations
a = 15
b = 4
print(f"Addition: {a} + {b} = {a + b}")
print(f"Subtraction: {a} - {b} = {a - b}")
print(f"Multiplication: {a} * {b} = {a * b}")
print(f"Division: {a} / {b} = {a / b}")
print(f"Floor Division: {a} // {b} = {a // b}")
print(f"Modulus: {a} % {b} = {a % b}")
print(f"Exponentiation: {a} ** {b} = {a ** b}")