Arithmetic Operators

Python / Basics

10 + 20                 # 30
20 - 10                 # 10
10 * 20                 # 200
20 / 10                 # 2

# power
10 ** 2                 # 100

# automatic floating point conversion
10.0 + (10 + 20)        # 40.0
20.0 - (10 + 10)        # 0.0
10.0 * (10 * 2)         # 200.0

# common division error
30 / 20                 # 1
30.0 / 20.0             # 1.5

# integer divison, quotient
20.0 // 20.0            # 1.0
30.0 // 20.0            # 1.0
40.0 // 20.0            # 2.0

# modulo, remainder
12.5 % 10.0             # 2.5
10.0 % 20.0             # 10.0

# built in numerical operations
abs(-20)                # 20
sum([1, 2, 3, 4])       # 10
min(1, 2, 3, 4)         # 1
max(1, 2, 3, 4)         # 4

# rounding values
round(2.945)            # 3.0
round(2.495)            # 2.0
round(2.945, 2)         # 2.94

'''
Michael Sjoeberg
2018-11-05
https://github.com/michaelsjoeberg/python-playground/blob/master/basic-syntax/arithmetic-operators.py
'''