The math module in Python provides access to mathematical functions defined by the C standard. It includes functions for trigonometry, logarithms, power functions, rounding, and common mathematical constants like pi and e.
Installation:
Built-in module (No installation required)
Key Features:
- Trigonometric and hyperbolic functions (sin, cos, tan, asin, acos)
- Logarithmic and exponential functions (log, log10, exp, pow)
- Rounding and remainder functions (ceil, floor, trunc, fmod)
- Mathematical constants (math.pi, math.e, math.tau, math.inf)
Code Example:
import math
# Calculate square root, factorial, and trigonometric values
print("Square Root of 16:", math.sqrt(16))
print("Factorial of 5:", math.factorial(5))
print("Value of Pi:", math.pi)
print("Sine of 90 degrees:", math.sin(math.radians(90)))
No comments:
Post a Comment