Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

Math

What is the math Module?

The math module in Python gives you access to mathematical functions like:

  • square roots
  • powers
  • trigonometry
  • rounding
  • constants like π (pi) and e

How to Use It

First, import the module:

import math

Then you can use its functions like math.sqrt(), math.pow(), etc.

📘 Commonly Used math Functions

FunctionDescriptionExampleOutput
math.sqrt(x)Square root of xmath.sqrt(16)4.0
math.pow(x, y)x raised to the power ymath.pow(2, 3)8.0
math.floor(x)Rounds down to nearest integermath.floor(4.7)4
math.ceil(x)Rounds up to nearest integermath.ceil(4.1)5
math.factorial(x)Factorial of xmath.factorial(5)120
math.piValue of πmath.pi3.1415…
math.eValue of Euler’s numbermath.e2.718…

🧪 Example Code

import math

print("Square root of 49:", math.sqrt(49))
print("2 to the power of 5:", math.pow(2, 5))
print("Floor of 4.8:", math.floor(4.8))
print("Ceil of 4.1:", math.ceil(4.1))
print("Factorial of 4:", math.factorial(4))
print("Value of pi:", math.pi)

🧠 Bonus: Trigonometric Functions

FunctionDescription
math.sin(x)Sine of x (in radians)
math.cos(x)Cosine of x
math.tan(x)Tangent of x
math.radians(x)Convert degrees to radians
math.degrees(x)Convert radians to degrees
angle = math.radians(90)
print("sin(90°):", math.sin(angle))  # Output: 1.0

✅ Summary

  • math is a built-in Python module.
  • It gives you math functions and constants.
  • Useful for basic and advanced math operations.

    Leave a Reply

    Your email address will not be published.

    Need Help?