Math Operators

All the common math operations such as add, subtract, multiply, and divide are included in Python. The following table shows all of the available math operators and the symbols used to perform them.

Addition
Unlike the other math operators, addition works with numbers and strings. # Addition of integers/floats x = 1 + 1 x = 3.3 + 2.2

# Addition of strings x = "hello" x = x + " world" print x   #output is "hello world"

Subtraction
# Subtraction of integers (or floats) x = 4 y = 3 x = x - y # x now equals 1

# Note: Subtraction does not work with strings

Multiplication
x = 3 x = x * 4 # x now equals 12

Division
x = 24 y = 8 x = x/y   # x now equals 3

Powers
# Using ** x = 3 x = x ** 3 # x now equals 27 which equals 3^3

Remainder
# Finding the remainder of 12/5 x = 12 y = x % 5  # y equals 2