Write about all modulr funcs in python along eith definition and example. Good answer dena bahut jyada marks ka hai question
Answers
I hope that it will help you..... ✌
Heya friend,
Here we go !!!
Module functions are those functions in python which carry various function under the module which a user do not require frequently, so hence the user has to call these functions for their utilization.
Various module functions which we will be discussing :-
1) Math
2) Random
3) Statistics
==============================================================
1) MATH
- math.ceil() - This function gives an integer just greater than or equal to the value given as parameter.
Eg - math.ceil(-2.5)
- 2
- math.floor() - This function gives an integer just lower than or equal to the vale given as parameter.
Eg - math.floor(-2.5)
- 3
- math.sin() - This function gives the sin() value of the parameter. Here, the parameter is in radians.
Eg - math.sin(90//2)
0.8509035245341184
- math.sqrt() - This function gives the square root of the value given as the parameter.
Eg - math.sqrt(16)
4
- math.pow(x,y) - This function takes two compulsory parameters say x and y and will give the value x raised to power y.
Eg - math.pow(2,3)
8
- math.fabs() - This function takes a parameter and displays the true value of the parameter.
Eg - a) math.fabs(12)
12.0
b) math.fabs(math.pi)
3.141592653589793
==============================================================
2) RANDOM
- random.random() - This function does not require any value and gives any random value between [0,1) , i.e. , this function can show any value between 0 and 1, where the value '0' is possible as a result but not 1.
Eg - random.random()
0.926
- random.randrange() - This function takes a range as a parameter and can take 3 parameters where only the 2nd one is compulsory and the rest two are optional. The first parameter is the starting value of the range, the second parameter is the terminating value of the range and the third one is the step value. The default value of first parameter is 0 and the third one is 1.
Eg - random.randrange(1,6,2)
5
- random.randint() - This function takes two compulsory parameter and gives any random value between them where both of those values given as parameter are also included.
Eg - random.randint(1,2)
1
==============================================================
3) STATISTICS
[This module works for list only and that too in ascending order]
Let us consider the list to be :- l = [1,2,3,4,5]
for us to understand
- statistics.mean() - This function gives the mean/average of the numbers in the list.
Eg - statistics.mean(l)
3
- statistics.mode() - This function gives the mode / the value with highest frequency(occurrence) in the list.
Eg - statistics.mode(l)
ERROR [As no value given in list has a frequency more than 1]
- statistics.median() - This function gives the median/the middle most value of the list.
Eg - statistics.median(l)
3
==========================================================================================================================================================================================