Title: Arithmetic Basics
Slug: arithmetic_basics
Summary: Arithmetic Basics
Date: 2016-05-01 12:00
Category: Python
Tags: Basics
Authors: Chris Albon

Create some simulated variables


In [1]:
x = 6
y = 9

x plus y


In [2]:
x + y


Out[2]:
15

x minus y


In [3]:
x - y


Out[3]:
-3

x times y


In [4]:
x * y


Out[4]:
54

the remainder of x divided by y


In [5]:
x % y


Out[5]:
6

x divided by y


In [6]:
x / y


Out[6]:
0.6666666666666666

x divided by y (floor) (i.e. the quotient)


In [7]:
x // y


Out[7]:
0

x raised to the y power


In [8]:
x ** y


Out[8]:
10077696

x plus y, then divide by x


In [9]:
(x + y) / x


Out[9]:
2.5

Classics vs. floor division. This varies between 2.x and 3.x.

Classic divison of 3 by 5


In [10]:
3 / 5


Out[10]:
0.6

Floor divison of 3 by 5. This means it truncates any remainder down the its "floor"


In [11]:
3 // 5


Out[11]:
0