Post thumbnail

Python Math Module Helper Cheatsheet.

Basic Math Functions 📖
  • math.ceil(x): Returns the ceiling of x, the smallest integer greater than or equal to x.
  • math.floor(x): Returns the floor of x, the largest integer less than or equal to x.
  • math.fabs(x): Returns the absolute value of x.
  • math.factorial(x): Returns the factorial of x, x!.
  • math.fmod(x, y): Returns the remainder of x / y.
  • math.frexp(x): Returns the mantissa and exponent of x as the pair (m, e).
  • math.fsum(iterable): Returns an accurate floating point sum of values in the iterable.
  • math.isfinite(x): Checks if x is neither an infinity nor a NaN (Not a Number).
  • math.isinf(x): Checks if x is a positive or negative infinity.
  • math.isnan(x): Checks if x is a NaN.
  • math.ldexp(x, i): Returns x * (2**i).
  • math.modf(x): Returns the fractional and integer parts of x.
  • math.trunc(x): Returns the truncated integer value of x.
Power and Logarithmic Functions
  • math.exp(x): Returns e raised to the power of x.
  • math.expm1(x): Returns e raised to the power of x minus 1.
  • math.log(x[, base]): Returns the logarithm of x to the given base. The default base is e.
  • math.log1p(x): Returns the natural logarithm of 1 + x.
  • math.log2(x): Returns the base-2 logarithm of x.
  • math.log10(x): Returns the base-10 logarithm of x.
  • math.pow(x, y): Returns x raised to the power of y.
  • math.sqrt(x): Returns the square root of x.
Trigonometric Functions
  • math.acos(x): Returns the arc cosine of x.
  • math.asin(x): Returns the arc sine of x.
  • math.atan(x): Returns the arc tangent of x.
  • math.atan2(y, x): Returns atan(y / x).
  • math.cos(x): Returns the cosine of x.
  • math.sin(x): Returns the sine of x.
  • math.tan(x): Returns the tangent of x.
Hyperbolic Functions
  • math.acosh(x): Returns the inverse hyperbolic cosine of x.
  • math.asinh(x): Returns the inverse hyperbolic sine of x.
  • math.atanh(x): Returns the inverse hyperbolic tangent of x.
  • math.cosh(x): Returns the hyperbolic cosine of x.
  • math.sinh(x): Returns the hyperbolic sine of x.
  • math.tanh(x): Returns the hyperbolic tangent of x.
Angular Conversion
  • math.degrees(x): Converts angle x from radians to degrees.
  • math.radians(x): Converts angle x from degrees to radians.
Special Functions
  • math.erf(x): Returns the error function of x.
  • math.erfc(x): Returns the complementary error function of x.
  • math.gamma(x): Returns the Gamma function at x.
  • math.lgamma(x): Returns the natural logarithm of the absolute value of the Gamma function at x.
  • math.pi: Mathematical constant π (approximately 3.14159).  🍰
  • math.e: Mathematical constant e (approximately 2.71828).
  • math.tau: Mathematical constant τ (approximately 6.28318, ratio of circumference to radius).
  • math.inf: Positive infinity.
  • math.nan: Not a number (NaN).

This cheatsheet give you a comprehensive 📚 path to understanding of the functions and methods available in the math module, useful for quick reference or study.

• • •

Latest Opinions

No Opinion so far...


No internet connection

Trying to reconnect...