import math is a Python import that provides mathematical functions and constants. Use it for trigonometry, logarithms, rounding, and accessing π and e.
# Python # description: math functions and constants import math # Constants print(math.pi) # 3.14159... print(math.e) # 2.71828... # Trigonometry angle = math.radians(45) print(math.sin(angle)) # 0.707... print(math.cos(angle)) # 0.707... # Logarithms and exponentials print(math.log(100)) # natural log print(math.log10(100)) # base 10 log print(math.exp(1)) # e^1 # Powers and roots print(math.sqrt(16)) # 4.0 print(math.pow(2, 8)) # 256.0 # Rounding print(math.floor(3.7)) # 3 print(math.ceil(3.2)) # 4 # Hyperbolic functions print(math.sinh(1)) # Factorial and GCD print(math.factorial(5)) # 120 print(math.gcd(48, 18)) # 6
math.sqrt(x): square rootmath.pow(x, y): x to the power ymath.exp(x): e to the power xmath.log(x): natural logarithmmath.log10(x): base-10 logarithmmath.sin(x), math.cos(x), math.tan(x): trigonometrymath.radians(x), math.degrees(x): angle conversionmath.floor(x), math.ceil(x): roundingmath.factorial(x): x!math.gcd(a, b): greatest common divisor