Professional Documents
Culture Documents
GE3151 PYTHON UNIT 4 NOTES EduEngg
GE3151 PYTHON UNIT 4 NOTES EduEngg
GE3151 PYTHON UNIT 4 NOTES EduEngg
CONNECT WITH US
WEBSITE: www.eduengineering.net
TELEGRAM: @eduengineering
-
INSTAGRAM: @eduengineering
Statement ,
Retai) B:) Prepaation.
Secuendo
data elamanb that
ave
called
aalled an
an empty
emply
A s t thaB Contai ns no elernan á
st
TELEGRAM: @eduengineering
CHENNAI DEPARTMENT OF
ScIENCE AND HUMANITIES
ECHNOLOey
Subject Code/Title: Unit:
Lwith n-
starb t h o ard ends
a luways
30, ho
> t =
I'a', 'b','e o, 2o,
> s t [3) =15
>ssAst
appondt) |add
an eament at tha erd of the.
Istppard (8) ,5,2,8
Jtst lst
ISyntax: tst.appand (obj)
Retums the Jawest ivdex of object| »>Ast L5,36,a'
inde C) h tha list. ves a alue Frorts lst. nder 'a')
object is not proscn h the lst.
Synlax kst. indez lot)
Tnsart objoc aB tho 6poctfiod s lst =l'a', 5, ] |
list.
insertC)inde n the bs lst insert (1, )|'a', '>, 5,8]
Suntar: st.insentl'indar, obj) Ast
pop ( [indax])
TELEGRAM: @eduengineering
SHENT DEPARTMENT OF
SCIENCE AND HUMANITIES
LCHNOLEa
Subject Code/Title: Unit:
Laoping n usts
ard tn @nslruc ave useful toorking twhen
Python's for Statement a
ann easy
easy way to
w thses. The for Va in s
eloment n a st.
acces each
a list
orarn b ind he sun eamens
st , 5,20 40] wsing Lang unchon
Sum:0
0r un 2at st= [u, 5, ao4]
Sum - Sunt
oionge (lenl Lt):
PrintSum ', Sun
Pront (index', )
opud Indet D
nde
&nder
index 3
TELEGRAM: @eduengineering Le
HENNAM DEPARTMENT OF
SCIENCE AND HUMANITIESs
Subject Code/Title: Unit:
Muta bit
The tst a dala shrcture This means the
muta bla .
name, So tua
Say that the olject b allasel
b=a ,
bua
True
then Vaial
both Vaaial
a7eferS an ohject ard assigh bza,
9He b the
Garne objoct. The assocakén of a Variable 'th a n
Dbjed b callel a
roference
Cloning Lst :
st i ,9,3
nlt=list (b1) Lmport Copy
Prnt(t, b) t w , 20, 30, 4, 50J
Pnot hut", nlst) nbl copy. copy
bt LiJ=7 stLo)= Loo
Print(st', lst) Pnot ( ' t t )
Printl'nlet, nlat)
Pnt'nls nl»t)
utped Oul pud
L,3,)
nlst ,a,3] t[oo, 2, 30
Lst [i 1o, 3 nbt [o, 20, 30)
nlst L2, 3)
List auametevs
hen wo pass a ist to a Juncticn, 1kaunctóne
a eeenco to the Rist.T he funclicn modfes a ist
lt);
de hsval
tingert 1,26)
72349
3-57
TELEGRAM: @eduengineering
DEPARTMENT OF COLOg SCIENCE AND HUMANITIES
Subject Code/Title: Unit:
Tuyle
Tupla a Seduorce Valuos of Came e dffean types
Sopaualad Comna. Tuple. a Sedueno 5 Unmulala ohje
pauenthesis to do.na ib elanant. Onea a tuplá has
Tuples u
|been crealod u Con'! dd elarnen a tupla or vomove
Croating Taples
Tple wth nteger data item
»t- (i, 2,3)
C1,2,3)
Tuple wth dtfouan dabatPeS
hello", 5.14, Tre , 75, 98)
e Creakng a
tuple with one elomant ,hvaned t ad
Cwhen
Cormma atte the elemen
Lo tl
n Tuples
Accessing Valuos
To access the Valug a
tuplo, iE u necessauy to we the
nder humber enclosad shuaua brackat aleng hith tha nama
tuple
u i n g suaa brackals sicin
>tup - ls,65, 95, Lwo)
t lo, o, 30,75,95)
pint ( tC31) tup L1:3)
Lss,95)
tuptup C:a
(15,65)
TELEGRAM: @eduengineering
ENGAY
NOL DEPARTMENT OF
SCIENCE AND HUMANITIES
Subject Code/Title: Unit:
Burntun(*t):
d e di tun ta,5)
u o : allb Output Sun 0 150
em Q7.b cohilo i lan lt
Te kum (duo, rem) Sum 9un 4 t
b,2)
a t (ipuk () Tetum Sum
b lput t) a Suntun (to,2o, 3o, 4o,5o)
c ti bun la ,5)
Print la)
Print le Print (Saum fun ( 1,2,3)
*Tuples be wel as koy fov a
Can
dvantae tuples dicd gauu hd Lst donne Lo uved as t
+ Tuples a e unmutable
Tuplos a sital pr rng dolo thH
Tleali thveugh tuple u fasl i write proBochad
than tecahng ove a Lst Mull pla Valucs Cone elarneLnga
TELEGRAM: @eduengineering
DEPARTMENT OF sCIENCE AND HUMANITIES
Dic tlonaios
Dre tionay s an unordaad collouluin elomenls . An e lorment
in dicfionary ho a koy value pau, Al elemant cn dicionary e
+Add elomant
Mambershup
Exampla
0paradions Doscripu 'no': 123
Creabng a dicionauy
th
S>> a : 5'Namc': 'AAA',
Croating a
alo
tha elomenlh by al'No
Accessg an Accosi ng
123
elemant usinq kep.
TELEGRAM: @eduengineering
Methods de lnouy
Dosc Tiption.
Methad Fxampto
troturn9 apy o diciona
Copye)s
a : a » : 'PythanMarks:953
Cory dicliorau? shoed
ts
Copy) br a.Copyt)
Pint (bY ctonay b
'$ub''Pyi hon', ' marla 95
Rotu nsa new vew of the|
tems a=
f I: "one , :two" dittionay itorns at diepla
a . itomst)
a st q dBctionauy tkay veala)
dclitems( [C1, 'one' , ' tuuo'J) upla a
keya) a . keys t) t displays liet of kas
a dicHonay
diel-keys (ti, 3)
Yaluas() a.valuos c) displays ist y values
| dictidnay.
aict valo» [ ['ona two)
Pop(kay) a.popl1) Remove tho elenent with
two' '3: kwo Koy and neturn Hs Valuo
SSS print la) om tha dictionay,
st Comprehensi on
Syntar
st= exprossion fo elomant t s t f conditional
this b eduivalond tb
or eloment st
Cond
exp
Containing an
expresSion 7ollouwod
ConSis ibrackols ,
a r eterns a
vesult ist.
vesult i st.
returns
Comprehension aways
The s t
The Codo into
tnto one
Dre
Combine thrrae lines Code
to
Proam i lb)]
i * 3 tor i
range
aubes
Print (cuhes)
Lo,1,8, 27, b4, 1257
we Can also
w the list Comprahensi on to Conbine the
elonenb tuv is
t
, 8D, 120, 8o, o, 24°, 1bo, 320, 4 8o
TELEGRAM: @eduengineering
above Code i equivalan! t
the
Histo qrams
the Verbica avis
A histo qram shous the roqueney on
Uport num np
eeg) mlab an mlob
tnpoyt matplo b
as plt
tinport ratplst Lb pypot
3s, b,1,8, 45,b5, 18,wo
X=1, 22, 23,
hun bins =5 jaca slor lue',
pll.hist [7,num_ bins,
n, ba, faths =
alpha = o.5)
plE Show C)
20
TELEGRAM: @eduengineering
TlstraBie J:3
8 3 , 5 3 ,1 7 , 2
Seloction Sort
a= tht (iput Enla the Sie f bst 23 q l T Exchane
pass
53, 3 , 1 9 , 1
Sortods}
8 , 14, 24, 27, 3
j- 53 33 CT) > Chare
8, 3 , 3 , 19, 1
TELEGRAM: @eduengineering
Exampla Prinl pnchased procddelail
8
3 Pnt )
SBock
qvrent
Prod L 7o; chocstale , ponab
total = total t pite 2
bisu 8 3
ponu); 56 Frus ;
prod [1J prod [«]-n
TELEGRAM: @eduengineering
Shuderds marks SBaBemant efurn avoLage (rosulb)
aYeuage (numters ); n name": "kumä" ASsesSme nt"
dof [a0.0, 971.0, 85.0, 92.0],
total Suwn(numlerS)
tota) floal ltotal) ASS 9nment ": 88D, T0. 0, 4.0
av tolal/( len lnurmers) "ltendanca ": [S5, 0, 90.0Jj
retun avg
ment
de getaYcuag (studond); na rame"; Vecna ASseg6
LO.,
AScesSment aveage (studend [ L tw0.0,12.9, 98.D
"; f82.0,88. D,).o]|
nssewmont hI) PSsianment
SBdent
AHendanta ": [eq.0,97.003
HS Sgnment =aveLage l
rame": "pacpak", *Pesess
man
L"nss gimend ") n3 nsS mer
5o. b
Loo.0, 81.o, 75.o,
AHlendante z
ayemge lStudont
Llo.o,15., 18,0]
Altendoance ) to' :]wo.D,
too.DJ4
ttondan
tO3 * na]
to =o.b ¥ ASsos Srent n2,
Studons [n,
=
HssgrmenBtoa
*AHerdbruHor Sudant s h u d a r s :
eli Store = 5 0 ;
Prnt peepa:"jet-lette -9rodo.
return B
gel avouage (na ))
else
e tun u " Pintclas Avengd Haiks"))
class_ aYaage (studanb);
Print(e_class_aveiage lstuadenh ))
de gel -
Deepak. o
50,
TS.0,
Lso.D, 67. D,16oj
w D , 15 0,
Lo. oj Lo,oj
A VeLage matks
KunaY: A
Veena O
BT
Deepak
Masks70.o
class AveLage
rade : B+
Class AveLago
TELEGRAM: @eduengineering
Two ma kg
Dofne list Sle t h exampla ?
A parl o a usf is callad ist slice. Tha Oporalibn m nJ
Telums tho. pavB the is orn nh dorr b nth dor includina
bu excluding the elamen a no
the elemond al the mh indet
ndet
0 t =
['a''b','e'", '2,ajJ
L:3]
?
by cloning uth example
list
wha do yau moan
w a asegh
the s a n e obyett.
to
>S a: J,2, 3] 2,aJ
b
a is
ita
i u
True names
names a and b,
a and b,
ist ha
two dfeand
dffecond
tha anothas
he anothe
The
The true
th ona
alias afo
made
oliasal. changes
cala
a
o,3,3]
with example
Defne naste bs that appoa as an elamant
b a list
A nestelet
c anothe isl.
S> nesl abc' , 2, o,ao
TELEGRAM: @eduengineering
5 Tllrale nagalve dexing s t with an exampl?
P
thdo xig for eduone
for typos
Prthonsuporb neqotire
lst takos the - i Ae,
ub. last t e on the
ke Th dor and So on
ilom has tha -a
to tha last
tho seCond
h'o'n
st L-
tupla ?
7 convert a String a
Hocw coverted a a tupla by uing tha tuploc
e
A Strng an
hunclon
togss uple ['proqammig9)
'a', 'm', 'm', 'i', 'n','7)
P ' o ' , 'a','¥
a,b = b, a
Print la,b)
usa t tplas ?
oint out the methads
yeturns tha numnkeu clemens hhich i afua
Count t) Tt to
the i e n 'elonment
TELEGRAM: @eduengineering
kow ae wa as etu rn Valuo»
Fxplan tuples
Can turn tuplos roturnn Vaue
funcBions
todo Suoap lx y)
e lurn y, z
a 35 ole a=26
b 35
a,b S a r(a,b)
"b: ",b
Pnnt('a=',a, Sion
Dato type Conver valuo/|
th Example (o) no tyre q
1 Depne coercion
C o e r ca o n
Data typo albo knowrn
to anotho cal type . s
Vaiable
tog) s z l o a (200)
t(950. 15)
tha contains
200. ddichionauy
chonauy
thato ntain
geneialo a
program
to genoLala
wrtaa
pythcn
Y,T*z)
nunbers t the form of
nunbe; ') Enlos a nunte
Enla a
n= nt (hpd { 2:, 4,3:9,4:
d f T : Ttr oz t ango , na1) 4 5:35
Prnt Cd)
ad eevse looku Valuo
Valuea
Corressonding
Covrosponding
5 Peina lookup the
indin9 the
indn
okue
tho procos9 Valua = did hay
orn dicionauy .teg) a
Hor
Tor tha
the a ven
kay the the
Procos9 nng he kay t
laokup
koveyse
Yen value
b remembaring
oremembering result results
Deine memorO"
e#echvely ejors ord tho returning
vetarnirg
ord he
tha nathocd pubs
Memorinauon
TELEGRAM: @eduengineering
CONNECT WITH US
CONNECT WITH US
WEBSITE: www.eduengineering.net
TELEGRAM: @eduengineering
-
INSTAGRAM: @eduengineering