CBSE
CLASS 12
CH-4
USING PYTHON LIBRARIES
SasikalaJayaprakash
Topics to be discussed
 What is library
 Importing modules in python program
 Using python standard library’s functions and
modules
 Creating python library
What is library
• A library refers to a collection of modules that together cater
to specific type of needs or applications.
• Library have one or more packages and subpackages
• Module is independent grouping of code and data(variables ,
definitions ,statements ,& functions). File extn .py
Syntax : help<module name> # to see docstrings , variables ,
constants , functions
Importing module
Two ways
• Entire module
import <module name>
• To import selected object from a module:
from<module name > import <fn name>
To import single object
To import multiple objects
To import all objects
from <module name > import *
library’s functions
• Mathematical function
len()
pow()
str()
int()
float()
range()
type()
abs(x)
divmod(a,b)
sum(iterable),sum(iterable,args),
max(iterable),max(iterable , args),
min(iterable),min(iterable,args),
Oct (integer)
hex(integer)
• String functions
<str>.join
<str>.split
<str>.replace
Using python standard library modules
• Random module
random() - 0 <=N<1
randint(a , b) a<=N<=b
random.uniform(a , b) floating point a<=N<=b
random.randrange(stop)
random.randrange(start , stop , step) (0,50,10)
• String module
string.ascii_letters
string.ascii_lowercase,
string.ascii_uppercase,
string.digits,
string.hexdigits,
string.octdigits ,
string.punctuation ,
capwords(<str>,[sep=none])
Creating a python library
• Package – collection of modules
_init_ .py – special file
Procedure for creating package
Creating package
• Decide about basic structure of package
• Create the directory structure having folders
with names of packages
• Create a __init__.py file in a package
Creating package
Geometry
volume
area
Rectangle() cube()
Square() cubiod()
Triangle()
Package
modules
functions
Creating Package(Geometry)
Importing package geometry , module
area
Area python file coding
Volume python file coding
CBSE-Class 12-Ch4 -Using Python Libraries - SasikalaJayaprakash

CBSE-Class 12-Ch4 -Using Python Libraries - SasikalaJayaprakash

Editor's Notes

  • #14 Inside geometry folder create python file,init file