2  Number

2.0.1 Number Types

Python has 3 types of numbers

type(1)
#> <class 'int'>
type(1.2)
#> <class 'float'>
type(1 + 2j)
#> <class 'complex'>

2.0.2 Arithmatic Operators

10 + 3
#> 13
10 - 3
#> 7
10 * 3
#> 30
10 ** 3
#> 1000
10 / 3 
#> 3.3333333333333335
10 // 3 # floor division
#> 3
10 % 3 # modulus
#> 1

2.0.3 Augmented Assignment Operator

x = 10
x = x + 3
x
#> 13

Shorter version

x = 10
x += 3
x
#> 13

2.0.4 Function with Numbers

round(2.3)
#> 2
abs(-2.3)
#> 2.3

using math module

import math

math.ceil(2.3)
#> 3
math.factorial(3)
#> 6