Python Lesson 4: Performing math calculations in Python using operators

  1. Addition using operators
  2. Subtraction using operators
  3. Multiplication using operators
  4. Division using operators
  5. Exponents using operators
  6. Remainder using operators
  7. Square Root Calculator

Computing math calculations is very common in programming languages. Performing math calculations in Python is simple. Enter the following code into the notebook and press Shift+ Enter:

1) Addition using operators

#addition
sum = 2 + 4
print(sum)
Notebook Output

2) Subtraction using operators

#subtraction
diff = 6 - 2
print(diff)
Notebook Output

3) Multiplication using operators

#multiplication
product = 5 * 5
print(product)
Notebook Output

4) Division using operators

#division
div = 20/4
print(div)
Notebook Output

5) Exponents using operators

#exponents 2 to the power of 2
exponents = 2**2
print(exponents)
Notebook output

6) Remainder using operators

#Remainder of 10 divided by 3
remainder = 10%3
print(remainder)
Notebook Output

7) Square Root Calculator

import math
#square root. This requires importing the math library
sq = math.sqrt(4)
print(sq)
Notebook Output

Recommended Books