Skip to content

Math operators

Python has all the standard arithmetic operators such as addition +, subtraction -, multiplication *, division /, and exponents **.

To quickly demonstrate these, let's define two variables a and b and execute some basic arithmetic operations

a = 1
b = 10

a + b
a - b
a * b
a / b
b ** 2

Dividing two int types returns a float

If you're familiar with languages like C or Python 2, you might be surprised to discover that Python 3 returns a float even when you're dividing two ints.

Exercises

Exercise 1

Feel free to play around with types and arithmetic expressions on your own. Define variables, run some operations, and even explore what happens if you multiply e.g., a str with an int.