🧮 math Module
Last Updated: 17th August 2025
The math module provides access to the mathematical functions defined by the C standard. It is very useful for Data Science students when doing calculations, statistics, ML algorithms, and data preprocessing.
Hinglish Tip 🗣:math module ka use mainly scientific calculations aur probability/statistics mein hota hai.Data Science mein kaafi jagah (log-transform, normalization, probability functions) ye direct kaam aata hai.
Import Math Module
import math
List of Math Functions:
- pow(base, exponent): Returns the value of base raised to the power of exponent.
import math
print(math.pow(2, 3)) # 8.0
- sqrt(x): Returns the square root of x.
import math
print(math.sqrt(25)) # 5.0
- ceil(x): Returns the smallest integer greater than or equal to x.
import math
print(math.ceil(2.7)) # 3
- floor(x): Returns the largest integer less than or equal to x.
import math
print(math.floor(2.7)) # 2
- fabs(x): Returns the absolute value of x.
import math
print(math.fabs(-2.7)) # 2.7
- factorial(x): Returns the factorial of x.
import math
print(math.factorial(5)) # 120
- gcd(x, y): Returns the greatest common divisor of x and y.
import math
print(math.gcd(12, 18)) # 6
- lcm(x, y): Returns the least common multiple of x and y.
import math
print(math.lcm(12, 18)) # 36
- fmod(x, y): Returns the remainder of x divided by y.
import math
print(math.fmod(10, 3)) # 1.0
- pi: Returns the value of pi.
import math
print(math.pi) # 3.141592653589793
- e: Returns the value of e.
import math
print(math.e) # 2.718281828459045
- . log(x): Returns the natural logarithm of x.
import math
print(math.log(10)) # 2.302585092994046
- log10(x): Returns the base-10 logarithm of x.
import math
print(math.log10(100)) # 2.0
- exp(x): Returns the exponential of x.
import math
print(math.exp(2)) # 7.389056098930656