Index
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
Function | Description | Example | Output |
---|---|---|---|
math.sqrt(x) | Square root of x | math.sqrt(16) | 4.0 |
math.pow(x, y) | x raised to the power y | math.pow(2, 3) | 8.0 |
math.floor(x) | Rounds down to nearest integer | math.floor(4.7) | 4 |
math.ceil(x) | Rounds up to nearest integer | math.ceil(4.1) | 5 |
math.factorial(x) | Factorial of x | math.factorial(5) | 120 |
math.pi | Value of π | math.pi | 3.1415… |
math.e | Value of Euler’s number | math.e | 2.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
Function | Description |
---|---|
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.