To use it, import the module
Python
import math Mathematical Constants :
Python
import math print(math.pi) print(math.e) #output 3.141592653589793 2.718281828459045 Square Root :
Python
print(math.sqrt(25)) #output 5.0 Power :
Python
print(math.pow(2, 3)) print(2 ** 3) #output 8.0 8 Absolute Value :
Python
print(math.fabs(-10)) #output 10.0 Ceil :
Python
print(math.ceil(4.9)) #output 5 Floor :
Python
print(math.floor(4.9)) #output 4Logarithmic Functions :
Python
print(math.log(10)) # natural log (base e) print(math.log10(100)) # log base 10 print(math.log2(8)) # log base 2 #output 2.302585092994046 2.0 3.0 Trigonometric Functions :
Python
print(math.sin(math.pi/2)) print(math.cos(0)) print(math.tan(math.pi/4)) #output 1.0 1.0 1.0 Combinations :
Python
print(math.comb(5, 2)) #output 10 Permutations :
Python
print(math.perm(5, 2)) #output 20| Purpose | Function |
|---|---|
| Square root | sqrt() |
| Power | pow(), ** |
| Absolute value | fabs() |
| Round down | floor() |
| Round up | ceil() |
| Remove decimals | trunc() |
| Logarithms | log(), log10(), log2() |
| Trigonometry | sin(), cos(), tan() |
| Degrees ↔ Radians | degrees(), radians() |
| Factorial | factorial() |
| Combinations | comb() |
| Permutations | perm() |