Python Math Module

Basic Mathematical Functions:

  1. math.sqrt(): Calculates the square root of a number.

  2. math.pow(): Raises a number to a specified power.

  3. math.exp(): Calculates the exponential of a number.

  4. math.log(): Calculates the natural logarithm of a number.

  5. math.log10(): Calculates the base-10 logarithm of a number.

  6. math.ceil(): Rounds a number up to the nearest integer.

  7. math.floor(): Rounds a number down to the nearest integer.

  8. math.trunc(): Truncates a number to an integer.

  9. math.degrees(): Converts radians to degrees.

  10. math.radians(): Converts degrees to radians.

Trigonometric Functions:

  1. math.sin(): Calculates the sine of an angle in radians.

  2. math.cos(): Calculates the cosine of an angle in radians.

  3. math.tan(): Calculates the tangent of an angle in radians.

  4. math.asin(): Calculates the arcsine of a value, returning the angle in radians.

  5. math.acos(): Calculates the arccosine of a value, returning the angle in radians.

  6. math.atan(): Calculates the arctangent of a value, returning the angle in radians.

  7. math.atan2(): Calculates the arctangent of y/x, returning the angle in radians.

  8. math.hypot(): Calculates the Euclidean norm (hypotenuse) of two numbers.

Mathematical Constants:

  1. math.pi: Mathematical constant π (pi).

  2. math.e: Mathematical constant e (Euler's number).

  3. math.inf: Mathematical representation of positive infinity.

  4. math.nan: Mathematical representation of NaN (not a number).

Hyperbolic Functions:

  1. math.sinh(): Calculates the hyperbolic sine of a number.

  2. math.cosh(): Calculates the hyperbolic cosine of a number.

  3. math.tanh(): Calculates the hyperbolic tangent of a number.

  4. math.asinh(): Calculates the inverse hyperbolic sine of a number.

  5. math.acosh(): Calculates the inverse hyperbolic cosine of a number.

  6. math.atanh(): Calculates the inverse hyperbolic tangent of a number.

Other Functions:

  1. math.factorial(): Calculates the factorial of a number.

  2. math.gcd(): Calculates the greatest common divisor of two integers.

  3. math.isfinite(): Checks if a number is finite.

  4. math.isinf(): Checks if a number is infinite.

  5. math.isnan(): Checks if a number is NaN.

Example of Usage:

import math

# Basic Mathematical Functions
sqrt_value = math.sqrt(25)
log_value = math.log(10)
sin_value = math.sin(math.radians(90))

# Mathematical Constants
pi_value = math.pi
e_value = math.e

# Trigonometric Functions
tan_value = math.atan(1)
hypot_value = math.hypot(3, 4)

# Other mathematical functions and constants can be used similarly

The math module provides a wide range of mathematical functions and constants for various calculations in Python.

Did you find this article valuable?

Support Namya Shah by becoming a sponsor. Any amount is appreciated!