Python Basics
Numbers and Math
| Operator | Example | Result |
|---|---|---|
+ | 7 + 2 | 9 |
- | 7 - 2 | 5 |
* | 7 * 2 | 14 |
/ | 7 / 2 | 3.5 (always a float) |
// | 7 // 2 | 3 (floor division) |
% | 7 % 2 | 1 (remainder) |
** | 7 ** 2 | 49 (power) |
print(round(3.14159, 2)) # 3.14
print(abs(-5)) # 5
print(max(3, 9, 2)) # 9
print(min([4, 1, 7])) # 1
print(sum([10, 20, 30])) # 60
import math
print(math.sqrt(16)) # 4.0
print(math.pi) # 3.141592653589793