Skip to main content

Math Module

import math
print("Constants/Properties")print(math.PI)print(math.E)print(math.PHI)print(math.SQRT2)
# ---------------print("Methods")print(math.absolute(-5)) # 5print(math.round(12.4)) # 12print(math.floor(4.8)) # 4print(math.ceil(0.3)) # 1
# ---------------print("Trigonometry Methods (Input values in radians)")print(math.sin(math.PI / 2)) # 1print(math.cos(math.PI / 3)) # 0.5print(math.tan(math.PI / 4)) # 1print(math.asin(1 / 2)) # pi / 6 or ~ 0.524print(math.acos(math.sqrt(2) / 2)) # pi / 4 or ~ 0.785print(math.atan(math.sqrt(3))) # pi / 3 or ~ 1.047
# ---------------print("Converting Between Radians & Degrees")print(math.radtodeg(math.PI / 2)) # 90print(math.degtorad(45)) # pi / 4 or ~ 0.785
# ---------------print("Logarithms")print(math.log(32, 2)) # Base 2print(math.log(8, 10)) # Base 10print(math.log(15.5)) # Natural Base (E)
# ---------------print("Roots & Powers")print(math.sqrt(64)) # 8print(math.power(4, 2)) # 4 ^ 2 = 16print(math.root(27, 3)) # 3
# ---------------print("Other")print(math.factorial(4)) # 4 * 3 * 2 * 1 = 24print(math.min(12, 5.5, 2.9, -5, 2)) # -5print(math.max(18, 46, 2.3, 19, 30.3)) # 46

A list of all the methods and constants that the math module has to offer.