Python mathmatics function

Python math module contains many methods for trigonometric and mathematical calcualtions. math.pi is the constant π:

>>> import math
>>> math.pi
3.141592653589793
math.e is the constant e:
>>> math.e
2.718281828459045
math.acos(x) returns the arc cosine of radian angle x. math.asin(x) returns the arc sine of radian angle x. math.atan(x) returns the arc tangent of radian angle x. math.atan2(y,x) returns the arc tangent of y/x. math.ceil(x) returns the smallest integer greater than x. math.copysign(x,y) returns -x if y<0 and x if y>0. math.cos(x) returns the cosine of radian angle x. math.degrees(x) converts a radian angle into its degree equivalent. math.exp(x) returns the exponential value of x with natural base. math.expm1() returns the natural exponential value of (x - 1). math.fabs(x) returns the absolute value of x. math.factorial(x) returns the x factorial x!. math.floor(x) returns the largest integer that is less than x. math.fmod(x,y) returns x % y. math.frexp() returns the mantissa and exponent as the pair(m,n) of x by solving x = m * 2**n, where 0.5 <= m < 1. math.fsum([...]) function returns the sum of [...] with higher floating accuracy. math.hypot(x,y) calculates the hypotenuse of a right triangle based on sides x, y. math.isinf(x) checks whether x is infinite or not. math.isnan(x) checks whether x in NaN (Not A Number). math.ldexp(x,i) is the reverse of frexp(), it returns x * (2**i). math.log(x[,base=e]) returns the logarith of x to the given base. math.log1p(x) calculates the natural logarithm of (x + 1). math.log10(x) caculates the base 10 logarithm of x. math.modf(x) calculates the fractional and integer parts of x. math.pow(x,y) calculates x raised to the power y. math.radians(x) converts a degree angle into its radian equivalent. math.sin(x) returns the sine value of radian angle x. math.sqrt(x) returns the square root of x. math.tan(x) returns the tangent of x. math.trunc() returns the truncated integer of x.


















endmemo.com © 2024  | Terms of Use | Privacy | Home