Python in-built function :
Python has many in-built function that are always available to the program . Some of them are related to mathematical operation .
- abs(x) : Returns absolute value of x , where x is any number ( Integer/float/complex)
Input :
>>>abs(-5) #integer
>>>abs(-63.2) # float
>>>abs(2-3j) #complex
Output :
>>>5
>>>63.2
>>>3.605551275463989
- pow(x,y) : Returns x to the power y value . x,y belongs to integer/ float
Input :
>>>pow(5,2)
>>>pow(2.3,5.3)
Output:
>>>25
>>>82.6337631255409
- min(x1 ,x2 ,x3.........) : Returns smallest argument
- max(x1,x2,x3,.........) : Returns largest argument
- bin(x) : Returns binary equivalent number of integer decimal number
Input :
>>>min(3,62,89,64,1,5,9)
>>>max(63,56,96,56,47,20)
>>>bin(2)
Output :
>>>1
>>>96
>>>'0b10'
Python Library :
In python programming language there is various library for various operation . we will discuss later in this tutorial . Now , we will limited only two important mathematical library which are math for mathematics function and cmath for complex mathematics operation .
- To use any library in python , we have import those library .
import math
or import cmath
- Mathematical function in math module :
- pi , e = constants value
- sqrt(x) = return square root value
- factorial(x) = return factorial value
- lox(x) = return natural log value of x
- log10(x) = return base-10 value of logarithm
- degrees(x) =returns radians to degrees
- radians(x) = return degrees to radians
- sin(x) = return sin(x) value in radians
- cos(x)=return cos(x) value in radians
- tan(x) = return tangent value in radians
- Similarly , sinh(x) ,cosh(x) and tanh(x) is for hyperbolic function .
- asin(x) ,acos(x) and atan(x) for inverse function in radians .
If you run this way :
Input :
>>>import math
>>>print(pi)
Output :
>>>Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
print(pi)
NameError: name 'pi' is not defined
This will show error . The right way to import python module/library is :
Input :
>>>import math
>>>print(math.pi)
Output :
>>>3.141592653589793
To use any library in python , firstly we have to import library and for use we have to call the library/module .
Next-> Python Random Function
Share: