Skip to content

Math

import math

Add

> 2 + 2
4

Subtract

> 4 - 2
2

Multiplication

> 2 * 4
8

Square

> 5 ** 2 # 5 squared
25
> 2 ** 7 # 2 to the power of 7
128

Square Root

> math.sqrt(49)
7.0

Division

> 17/3
5.666666666666667
> 50/2
25.0 # Always a float

Floor

> 17 // 3 
5
> math.floor(5.2)
5

Ceil

ceil(val)

Mod

> 17 % 3
2

Sum

>sum([2, 3])
5
>sum([3.2, 2])
5.2

>>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
0.9999999999999999
> math.fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
1.0

Infinity

infi = math.inf
neg_infi = -math.inf