COMPUTER SCIENCE
CLASS XI
CHAPTER 14
PYTHON MODULES
HUMA YASMIN, PGT(CS)
K V IOC NOONMATI
PYTHON MODULE
■ It is file which contain Python definitions and
statements.
■ It is an independent grouping of code and
data(variables, definitions, statements and functions).
■ It can be re used in other programs.
■ It can depend on other modules.
■ It can include executable code.
■ File extension is .py
Prepared by Huma Yasmin, PGT(CS)
Relation between MODULE,
library and package
■ Module is file which contain Python definitions and
statements.
■ Package is a directory of Python modules
■ Library is a collection of various packages
Prepared by Huma Yasmin, PGT(CS)
PYTHON LIBRARY
Some commonly used Python libraries are :-
■ Python standard library
■ NumPy
■ SciPy
■ tkinter
■ Matplotlib
Prepared by Huma Yasmin, PGT(CS)
IMPORTING python MODULES
■ Python provides “import” statement to import
modules in a program.
■ The import statement can be used in two ways
➢ To import entire module
➢ To import selected objects from a module
Prepared by Huma Yasmin, PGT(CS)
IMPORTING python MODULES
a) To import a module – import < module-name>
To import two modules – import module1, module2
Now to use any function of a module
<module>.functionname( )
ex:-
This way of referring to a module’s object is called dot notation.
Prepared by Huma Yasmin, PGT(CS)
IMPORTING python MODULES
Note :- Name of a module is stored in a constant
_ _name_ _
Ex:--
Prepared by Huma Yasmin, PGT(CS)
IMPORTING python MODULES
b) To import selected objects of a module –
from <module> import < object-name>
■ To import single object –
from math import pi
■ To import multiple objects -
from math import pi , pow
■ To import All objects –
from math import *
Prepared by Huma Yasmin, PGT(CS)
Module aliasing
Syntax :-
import <module-name> as <alias - name>
Prepared by Huma Yasmin, PGT(CS)
Member aliasing
Syntax :-
from <module-name> import <function> as <alias - name>
Prepared by Huma Yasmin, PGT(CS)
Math module
NOTE-
Ceil function – it returns the next integer value
Floor function – it returns the integer part
Prepared by Huma Yasmin, PGT(CS)
Random module
This module is used to generate random numbers.
It generates
random number
between 0.0 & 1.0
It generates random number
in range 10 to 20 (both
included)
Prepared by Huma Yasmin, PGT(CS)
Random module
It generates random
number between 0 &
9
It generates random
number between 5 &
9
Prepared by Huma Yasmin, PGT(CS)
Statistics module
mean( ) – It calculates the mean/average of the numbers in a list.
Prepared by Huma Yasmin, PGT(CS)
Statistics module
median( ) – It returns the middle value of the numeric data in a list.
Prepared by Huma Yasmin, PGT(CS)
Statistics module
mode( ) – It return most repeated value from a list.
Prepared by Huma Yasmin, PGT(CS)
Thank you