Introduction to Python Modules Class 11 Important Notes

Share with others

Introduction to Python Modules

Python Modules
Python Modules

Module : A module is a Python file where functions, constants and variables are defined. Extension of Python module is .py

Advantages of Modules in Python

  1. It makes the code reusable, means we can use the same code in different programs.
  2. It makes our code easier to understand.
  3. It help us to organize or manage our code in Python.

Introduction to Python Modules

Importing Python modules

There are three ways to import a module in Python.

1. Using import statement : This is one of the most common way to use module in Python. This method allow us to access all the functions/objects defined in the module. for example : to use math module, we can write —

import math

To use more than one module like math and random in our code, we can write :

import math, random

After importing module in our code, we can access a specific function by writing:

<module name>.<function name> like math.sqrt

2. Using ‘from’ statement : This method allow us to import specific function of a module. for example

from math import ceil

To import more than one function of a module, we can write

from math import sqrt, fabs

3. Using import* statement : This statement can be used to import all functions of a specific module like

from math import*

Python Modules
Python Modules

Types of Python Modules

There are two types of Python modules:

1. Built-in Modules

2. User defined Modules

1. Built-in Modules : There are many built in modules in Python Library. Some of the common built-in modules are:

  1. Math module
  2. Statistics module
  3. Random module

1. Math module : This module has many mathematical functions like ceil, floor, sqrt etc. Let we discuss few functions of math module.

a. floor(n) : This function returns the largest integer which is less than or equal to n. for example

import math

Output : 23

import math

Output : -41

import math

Output : 23

Introduction to Python Modules

b. ceil(n) : This function returns the smallest integer which is more than or equal to n. for example

import math

Output : 24

import math

Output : -40

import math

Output : 24

c. pow(m, n) : This function returns m raise to the power n. for example

import math

Output : 8

import math

Output : 16

d. sqrt( ) : This function return the square root of a number passed as argument. for example

import math

Output : 4.0

import math

Output : 11.0

import math

Output : Error

e. fabs( ) : This method return the absolute value(positive value) of a number passed as an argument. for example

import math

Output : 9.0

import math

Output : 78

import math

Output : 65.78
Python Modules
Python Modules

f. sin( ) : This function returns the sine of value passed as argument. for example

import math

Output : 0.8939966636005579

import math

Output : 0.0

import math

Output : 0.8509035245341184

NOTE : Value passed in this function should be in radian

Introduction to Python Modules

g. cos( ) : This function returns the cosine of value passed as argument. for example

import math

Output : -0.4480736161291701

import math

Output : 1.0

import math

Output : 0.5253219888177297

NOTE : Value passed in this function should be in radian.

h. tan( ) : This function returns the tangent of value passed as argument. for example

import math

Output : -1.995200412208242

import math

Output : 0.0

import math

Output : 1.6197751905438615

NOTE : Value passed in this function should be in radian.

i. pi : It returns mathematical constant. for example

import math

Output : 3.141592653589793

j. e : It returns the mathematical constant

import math

Output : 2.718281828459045

Introduction to Python Modules

2. Statistics Module : Functions of statistics module are discussed below:

a. median( ) : This function returns the median of the data. Median means middle value. for example :

import statistics
print(statistics.median([23, 45, 56, 67, 78]))

Output : 56

b. mean( ) : This function returns the average of the data passed as an argument. for example

import statistics
print(statistics.mean([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))

Output : 5.5

c. mode( ) : This function returns the mode ie a number with maximum number of occurrence. for example

import statistics
print(statistics.mean([1, 2, 1, 4, 1, 2, 3, 2, 1, 5]))

Output : 1

3. Random Module : Click here for notes and questions

Python Modules
Python Modules


Q1. Write the output of the following :

import math

a. print(math.floor(65.7))
b. print(math.ceil(-78.9))
c. print(math.sqrt(math.floor(64.56)))
d. print(math.fabs(-90.78))
e. print(math.ceil(70.03))
f. print(math.sqrt(121))
g. print(math.pow(2,5))
h. print(math.pow(math.sqrt(16),math.ceil(2.96)))
i. print(math.sqrt(math.ceil(35.21)))
j. print(math.cos(0))

a. 65
b. -78
c. 8.0
d. 90.78
e. 71
f. 11.0
g. 32.0
h. 64.0
i. 6.0
j. 1.0

Q2. Write the output of the following

import math

a. print(math.ceil(35.7))
b. print(math.ceil(-98.9))
c. print(math.sqrt(math.ceil(63.01)))
d. print(math.pow(9,math.sqrt(4)))
e. print(math.pow(10,-2))
f. print(math.sqrt(81))
g. print(math.pow(4,-2))
h. print(math.pow(math.sqrt(100),math.ceil(-3.96)))
i. print(math.sqrt(math.ceil(48.10)))
j. print(math.tan(0))

Solutions : 

a. 36
b. -98
c. 8.0
d. 81.0
e. 0.01
f. 9.0
g. 0.0625
h. 0.001
i. 7.0
j. 0.0

Q3. Write the output of the following :

import statistics

a. print(statistics.mean([1,2,3,4,5]))
b. print(statistics.median([1,3,5,7,9]))
c. print(statistics.median([1,3,5,7,9,11]))
d. print(statistics.mode([1,3,3,2,2,3,4,5,2,3]))
e. print(statistics.mode([23, 22, 25, 26, 23, 28, 23]))

Solution :

a. 3
b. 5
c. 6.0
d. 3
e. 23

Disclaimer : I tried to give you the correct Notes of ” Introduction to Python Modules ” , but if you feel that there is/are mistakes in the Notes of Introduction to Python Modules given above, you can directly contact me at

MCQ of Computer Science Chapter Wise

1. Functions in Python

2. Flow of Control (Loop and Conditional statement)

3. 140+ MCQ on Introduction to Python

4. 120 MCQ on String in Python

5. 100+ MCQ on List in Python

6. 50+ MCQ on Tuple in Python

7. 100+ MCQ on Flow of Control in Python

8. 60+ MCQ on Dictionary in Python

Important Links

100 Practice Questions on Python Fundamentals

120+ MySQL Practice Questions

90+ Practice Questions on List

50+ Output based Practice Questions

100 Practice Questions on String

70 Practice Questions on Loops

70 Practice Questions on if-else

Computer Science Syllabus 2021-2022.

Informatics Practices Syllabus 2021-2022

Class 12 Computer Science Chapter wise MCQ

Share with others

1 thought on “Introduction to Python Modules Class 11 Important Notes”

Leave a Reply

%d bloggers like this: