0% found this document useful (0 votes)
3 views

Python Libraries

Uploaded by

om dixit
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)
3 views

Python Libraries

Uploaded by

om dixit
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
You are on page 1/ 6

>Relation

|he>M'odole ’Module :
Pthonibraries Modules
a) 2) A When
together
Apython varables,dloases
Package statements module is
funcHons, Aaode Pyfhon
1) m-needs
klas is easler Thlcontain
s A Notes - clasfellov
Functions library commonly
module
extenslon cLpproach, we
i to
program functions
packaae blw pe understand, break is
Apythan A Sub-rmodules. / US
of module or ed simply
Module which
is pactage this package
comprisea that a Using
ibrary. m
pr
a s odule
Hle js oqramnto
ismodules, a Chapter’4
collecion a Phckage test pexform
directory a called file Py
is 3main that
ftle thon
&
py that
contalning & Contain
modularlsation,
maintain related
of(or
lbrary ibrarles
relabed
tolder) component6 contalns

i= GOUrce tasks.
chould
module
each
ofeython pethon py
modulea
i code thon 1CPPL
Date:
2094
PageNo. 16lo41
make
dellnition,
that for code.
the
modules.. generic
works proqrarm
Page No.

dlassfalov

python.
Library many package in
collecton of Library & packaga.
Library Is a diference blw
no
Cnenerally there is

Script Vs Module -
> Pthon
Scrigt
python fle that intends to be e ruh directly.
Hscript s a should do &omething.
run it,t
Nhen you

Module
python file that iad Intends to be imporked
A madale is a
into scrlps or othex mod ules.
clases , funcion & Varlables intendet
9t often defines mermbes ike
to be USed n otber Ale that import it

Sonpk Module
def add (a, b): def add la, b) :
return a+ return(o+b)
yesult = add ( 6,)
printGresult)

Advantoag of Python Modules i

Putting code in modules ls U5edfol because of the abilib o


impart the
A modole can be
Used In some other python ode.. Hence,
oroYides the facluty d code
A module allow us to reusability
Sirollar types o
logically organise our python coae
attiboto can be placed in module.
44 reduces the Complextty aslngle
the pragram, to a large extent,
CPPL
Date: 1 20
dlassfellow Page No.

DUsing import statement:


"Import <module name >
import <module1 >,<module 2>-
moduen
accesS a particolar method fromn any module,
<Madule Name.functionnameO

2) Uslng from atatement:


USed to accesS
specific attributes from a modole.
" from Kmodule > mport <function. -Dane >
" from <module >import <Punchion-mame >, <fonctonname 2>
<funothonname n >
Slo a partcolar method from any module,
accers
funchioo Name O
Notes -

Random Modulei
Used when we requlre SUch no. that are not known earlier.
ex- Captcha or any serial numn bersthen, in tbis situaton we
need O random no.
Pseudarandom no. or Lottery teca ptcha Cike in Lagln fom
a
random no. genera tor to qen evate which image is to
be kn Dbh to the USer.

Cormputer gaina Involving throwing a dice, picking a no. Ox

plcktng a con.
Jo Use randomi fun Mon wehave to imgort random module,

*
Swffle)
* method *
method:
exi- stcing Cholce) 94
Randomn
Random clasfellow
Sule This This RandintO
Uniform) wbich
RandrangeDfunchan
inteqer
Returns method
dom.Choice(sseqvence >) doe
method or
listist First not
Functon:-
a bl mod
rondorm any fin
X require ule
in can no.
isnvmbers.
retorns3t given in
other
replace sufle y5ed Is
elernent qenerate Python:
This
lower This
lower& or an 1
seqyencee
the selectlon
randomfor method brt
& any limitmethod arqument.
fram excludingo)
return tems upper
floating
paint i-
o the &take This
None second limit yalue
the qlven
glven 2para metbod
blo
seqvence. from no. Retorn
no is &1o Date:
PageNo. 1CPPL
list always
list, metera,b)
blo b/ Ploat I20)
tuple no.
returna (Hnetucling
extluding
gien b/sO
or
in
an &
1
code,
I120
followlng e)
Page
No. NaNUMBER]+ ") = )
Data
:
the =
end end end
from C*5))
(20+random.rondomC*5)
O*5),
rondom.random5)
exected
minmum [N]+STR)
3) randam-random
Yandom-randoo
(O, !=:
6TRINGCN]
while t1
outcomes randomrandintNUMBER cade:
&, NE
NLI
imum (sIRIN folloing
posslble O
max BSE =
NUMBER ISt
Yandom+ + (20+
import
20 (20 25 24
29 24
223
24 21
"C print N-1.
N L0#
classfallow Progzama the NUM8ER= IO ON the (int intl
LE#
NO#
Qre = NB# (IntCint 24 21
STRING # IE#
specify NE Conaldey printprintprlntprint 22 22
23 21
-what ES# t#
NS#EC 20
23
2
C) a.) b)
b) c)

You might also like