Math Library
Python’s math library provides mathematical functions and constants, allowing you to perform various mathematical operations easily. Importing the Math Library To use the math library, you need to import it into your Python script:
import mathCommonly Used Functions and Constants
Square Root
import math
result = math.sqrt(16)
print("Square root:", result)
# Output: Square root: 4.0Trigonometric Functions
import math
angle_radians = math.radians(45) # Convert degrees to radians
sin_value = math.sin(angle_radians)
cos_value = math.cos(angle_radians)
print("Sine:", sin_value) # Output: Sine: 0.7071067811865476
print("Cosine:", cos_value) # Output: Cosine: 0.7071067811865476Logarithmic Functions
import math
log_value = math.log(10, 2) # Log base 2 of 10
print("Logarithm:", log_value) # Output: Logarithm: 3.3219280948873626Constants
import math
print("Pi:", math.pi) # Output: Pi: 3.141592653589793
print("Euler's number:", math.e) # Output: Euler's number: 2.718281828459045These are just a few examples of what the math library offers. Explore the official Python documentation for math to discover more functions and capabilities.
Advanced Concepts
Feel free to further expand on this section or modify it according to your needs.