0% found this document useful (0 votes)
11 views17 pages

Understanding Python Modules and Libraries

The document provides an overview of Python modules, libraries, and packages, explaining their definitions and relationships. It details how to import modules using various methods, including module aliasing and member aliasing, and highlights commonly used libraries such as NumPy and Matplotlib. Additionally, it covers specific modules like Math and Random, along with their functions for statistical calculations.

Uploaded by

msgupta97122
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views17 pages

Understanding Python Modules and Libraries

The document provides an overview of Python modules, libraries, and packages, explaining their definitions and relationships. It details how to import modules using various methods, including module aliasing and member aliasing, and highlights commonly used libraries such as NumPy and Matplotlib. Additionally, it covers specific modules like Math and Random, along with their functions for statistical calculations.

Uploaded by

msgupta97122
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like