In Python, the math module provides a wide range of mathematical functions for numerical operations. These functions include basic arithmetic operations, trigonometric functions, exponential and logarithmic functions, and more. Here's an overview of the math module:
To use the functionalities provided by the `math` module, you need to import it:
import math
The math module provides functions for common arithmetic operations:
The math module provides functions for trigonometric operations:
The math module provides functions for hyperbolic operations:
The math module also provides several mathematical constants:
Additionally, the math module includes functions for rounding, flooring, ceiling, factorial, greatest common divisor (GCD), least common multiple (LCM), and more.
Example Usage:
import math
print("Square root of 16:", math.sqrt(16)) # Output: 4.0
print("2 raised to the power of 3:", math.pow(2, 3)) # Output: 8.0
print("Sine of 45 degrees:", math.sin(math.radians(45))) # Output: 0.7071067811865475
print("Natural logarithm of 10:", math.log(10)) # Output: 2.302585092994046
print("Value of pi:", math.pi) # Output: 3.141592653589793
The math module is a powerful tool for performing mathematical calculations in Python. It provides a wide range of mathematical functions and constants, making it easier to work with mathematical operations in your Python programs.