Python math functions

a=12
b=5
print(a+b)          # 17 , sum of two numbers 
print(a-b)          # 7 , subtraction  of two numbers 
print(a*b)          # 60, product of two numbers 
print(a/b)          # 2.4, quotient of two numbers 
print(a//b)         # 2 , floored quotient   
print(a%b)          # 2,  remainder of division 
print(a**b)         # 248832, a to the power b 
print(pow(a,b))     # 248832, a to the power b 
print(divmod(a,b))  # (2,2) ,the pair (a // b, a % b)

Importing Math library

You may get error saying about the missing math library need to be included before using these functions.
NameError: name 'math' is not defined
Just add this line before using the functions
import math
bitwise operatorsUsing bitwise operators
floor & ceilGet lower or higher integer from the input number
fabsabsolute value of input number
factorial!n is the factorial of input number n
copysignCopy sign of one number to other
fmodModule of two input numbers
frexpGetting mantissa and exponent of input number
ldexpGetting the number by using mantissa and exponent
fsum()Sum of elements of iterable object
isfinite()checking the number is finite or not
isinf()checking the number is infinity or not
isnan()checking the number is NaN or not
modf()Separating fraction and integer parts
remainder()remainder of one number with respect to other
round()Rounding number to nearest float or Integer
trunc()Integer part of a number
exp()e raised to the power x
expm1()e raised to the power x -1
pow()x to raised to the power of y
sqrt()Returns square root of a number
logarithm
log(x[,base])Log of x using input base ( optional )
log1p(x)Log of 1+x using base e
log2(x)Log of x using base 2
log10(x)Log of x using base 10
Trigonometric functions
acos(x)arc cosine of x ( input in radian )
asin(x)arc sin of x ( input in radian )
atan(x)arc tan of x ( input in radian )
cos(x)cos of x ( input in radian )
sin(x)sin of x ( input in radian )
tan(x)tan of x ( input in radian )
acosh(x)inverse hyperbolic cosine of x
asinh(x)inverse hyperbolic sine of x
atanh(x)inverse hyperbolic tangent of x
cosh(x) hyperbolic cosine of x
sinh(x) hyperbolic sine of x
tanh(x) hyperbolic tangent of x

Constants

math.pi π=3.141592
math.e e=2.718281
math.inf floating-point positive infinity, -math.inf is floating point negative infinity
math.nan A floating point not a number.
Standard DeviationStandar Deviation for a list of numbers
Random NumberGenerate Random integer and float


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer