GE3151 PYTHON UNIT 4 NOTES EduEngg

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

CONNECT WITH US

CONNECT WITH US

WEBSITE: www.eduengineering.net

TELEGRAM: @eduengineering
-

INSTAGRAM: @eduengineering

 Regular Updates for all Semesters


 All Department Notes AVAILABLE
 Handwritten Notes AVAILABLE
 Past Year Question Papers AVAILABLE
 Subject wise Question Banks AVAILABLE
 Important Questions for Semesters AVAILABLE
 Various Author Books AVAILABLE
Subject Code/Title: Unit:

NIT- STS TUPLES DICTIDNARIEs


Lists st operations, list stcos s t methods , list loop,

alasng. cloning ists, Ust parameters; Tuplos;


mutab;by ,

return vaua Dicionaries


tuplo assgnment, tupla as
methods advancod list procossing.list Cormprehensin
operations ard studanb
stucenb marks
lustrati ve programs Stmple Sorting, histogvam ,

Statement ,
Retai) B:) Prepaation.

Secuendo
data elamanb that
ave

A data structura a roup of a


Data StucBure dejines
name
undeY one
Put togethar data inin aa Computev.
Computey .

and ovganixing dala Python. Tn


cular way of Storing t python. In the
the
Parti msic dala'
s r u c B u r e
the most spacifie index.
Secuona ts each element has a

data Structuro automatically


Saduen o Zero ard is
Starb from
undex Valuos elemen n
en the
the Secuence
The
The the nex
ncremented for
List Values, Tha
Valuos i a üst a v e
is a Sequenca. of a s elemenb .
also callod
alled as elhments
ist
separatod Valuos, ard it bracke [.. ] and
brackeb [
Comma.
elementu
must enclosed by cLar
List must b.
Valuos
the
Syntax List Variable val1,vals...
elements
element
list that it can have
The
The key feature of a
koy Same dala types
daBa ypes or

that belong to dferenb


t = [ 4 , b, 8]
Fg
Ast 20,. b8hello', True,Python
:

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:

A List with» anot har U'st called Nastad l?st


n t = [i,5,8, Laa a, 'abe'], 4
accass tha elom ents tha s t
accos
usad
access Valuos n ust sduare bracket
are to
To the ndev,
l u e stored at
the ndex to jel
along t hoperation s
Sce along usea to acess
Valuos t sst
t
and also s c e

Syntaz S e d lst [start:sthp : shop]


output
F s t elamen b [5, Lo, 15,20,
25, 30]
At L5, o, 15, 2o, 5, 3]
st elemenb ", bt)
Print Firs element 5

Pint Frst elarnent ", lst[J)


st [1:3J", Jot[1:3])
st [:3 [ , 5]
pint( t[:2: [s,5,25]
p n t s t [::2}", kt[::2]
Updating Valuas in st sido
nsido
mutabla of any element
The valuo
sts aro .

be changed at any point of time.


The elamen
tha Lst c a n ndex
a c c e s s ble with their ndax Va lua ,the
Of the
of
Lst
the Ust are

Lwith n-
starb t h o ard ends
a luways
30, ho
> t =
I'a', 'b','e o, 2o,
> s t [3) =15
>ssAst

T ' a ' , , ' e ' , 15, 2o, 80, 4o].


7a versing a list meanS accossing all tha elamenb
Ver sin9 ist
Tra a

s . Travern9 Can e performed by using for loaop.


the
st L98, bb. =
13
, 58, 48,57 18
f o rfor lst
oP 6b
73
Print (1 58

TELEGRAM: @eduengineering SHENNA DEPARTMENT OF


SCIENCE AND HUMANITIES
NL
Subject Code/Title: Unit:

>>> nlst Li,a, 3, [3,4, 5], J


tE3]
[s,4,5 3

for for i nlot [3,4,53


Print l b.

LigE 0pera tions

Descn ption Erample. oud put


Oporation
Returns length of ltst en CL1, 3,33) 3
lan
Concatenahon Joins two ksts. Ths bdone a [o, 5,b]|
'z7|Lo,5. 6, a,
sb [a, a'
b operator >> atb a','']

elomans tha 'st.


lsk =[1o, 'a']|
Ist =[to, a'3
,'a', 1o,a)
Repelition Ropeab
Tt perforad hy'* opeiator.
chacks f he value b 'a [io,2o30] False
Present the st

chocks 1f tha valuo n o t ' o not


nol n in the ltst. Truo
Prosent
Retuns maximum valuo ss lst = [2, b8,45J
max max (lst) 13
t h a list

ReturnsS mini mum valu Lst- [o, 2, 4e] 0.


mun > mun (dst)
nthe liet

Add the values the ist, |»s lt Llo, 20,30]


-

Sum that has numbers Aum Clst)

new sortod st. |>> lst- L5,2,4,,C,24, 5,1]


Retuns a
Sorted (at) [5,2,4,7, ]
Sorted Estis not
The orinal
Sorled
all items in > lat = Liy 2, 3] True
Returns True i
al iterebla are truc sall llat)
, otherwise l s t LO,),2J
ttuTns eee Falsa
TELEGRAM: @eduengineering
DEPARTMENT OF FHENNA
HSTÍio sCIENCE AND HUMANITIES
Subject Code/Title: Unit:

Redurrns Tue ans eleman> lst=[o, !,2]


tn the ist is truo.ftha > any ( st)
it 7otums >st=[3
st Ys empty > any clst) Fa lse
False.
ist ma thods.
has Various
to help
fo
procranmmers
woTk
Python methads

effrci ontly toth sls.


0Paratien Desciption ard Syntax Example Outpat
Counbs the nunber of times lstlst- [5,6,7,8, 7.4
Countt an elemant appears à tha Ist.Count lb) 3
st
ntax: ist.Count Cobi)
Prpords an elomant to tha kst l a s | lst [ i , 5,2]

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

Remove o dololes objac >> lst -5, 6,23,£

Yemovet) om the ist. Ist.remove (a3) |I5,b, 46]


Syntaz ist. remove (obj) Ast
Rono ve the
elernent at the lst Aat le,2o,395, =

Spodfiaindex from the s .


Popt Tncdex an optional paiome.ter st.popt
f no uhdex is speuifadthen pop la) Le, 20,51
Temove tho last elemenl fom lst
he
Syntax kst .

pop ( [indax])
TELEGRAM: @eduengineering
SHENT DEPARTMENT OF
SCIENCE AND HUMANITIES
LCHNOLEa
Subject Code/Title: Unit:

Reverse tho elamenb the- ||> t =[15,N,28, 387


reverseL t re voTSe (
st 9,28,17,15)
Synat Rst.rover se t)
=[8,4.415,.J
the elomenb n tho lst s totSDTtC ) C4,6,12, i5]|
SoTt C SoT
)
Syntor 'st. Sort

elaman tha Est to |Lst =['a','b', J| T'a'b', to,


extendt dds tha anothe ist using > st 30 [w, 20,30
the end >s st). extend (kot2)
+lor) t on a ist i Similai o o,30]
to using extendc) Ast
extend (Lsta) bta
Est1.
Syntax

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 .

elemenb Can be eplatad iserted or ronov. A sice operoBor


On the. left sde f an assnment opoualuin can update Sig

rmulliple elemens a tst


st , 'a"',r1a', 7
J= 75
lst [:3J-[85, 'abc'] oulpd
C15,85, abe', 15]
print (bt)
List aliasing_"
An bjec wth more than One Teerance hab more ond
than one

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 :

Assgnment sBalemanb python do no Copy objecb


coP
ketveen tuo objecb qo muta ble
They Sumply bnangs Croale

Sequence aCopy an exisBng oed may recured,


So that
Cn oliect con e Chonga without afaking another
another.
In lisb, cloning opeLauon Can e ad b Create a copy
coP
o an exisin st . So tha changos mode un one
Copy of ust
twill not afect another The
The Cop
Copy Contains the Same elemen
as the original.

TELEGRAM: @eduengineering NS A DEPARTMENT OF


ECHNOLOo SCIENCE AND HUMANITIES
Subject Code/Title: Unit:

Mathod1 ) st () funcion Hathod Ia. Cory.copy )unlion


no ist= lst lold Lst) nowust:copy.cryloist)
'

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

Paua me ter, tha aalla See tha change the bsl

lt);
de hsval
tingert 1,26)

Ast[ab, 3s, 49, 57


Print Belore thsevlon ", lbt)
insval (ttS
Print( nfle hserun " bst)

t and the Vaiable st an ataes yor


Tho
Tho paamola
tho Same objocd

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

elamenb rom the tupla. .

Croating Taples
Tple wth nteger data item
»t- (i, 2,3)

C1,2,3)
Tuple wth dtfouan dabatPeS
hello", 5.14, Tre , 75, 98)

Lhello', 3.14, Tmo ,


15,18)

Cm) Nosted Tuple


t=lis, 18,45, (7s,
'abe ", 37.98)

tuple with ona elament i Soma oha! dtfrent


Croaking a

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:

Basi Tupla oeialons


OLalon Deseiption Exampla Cupu
Concalanalin Adding tupla elarnands al tha
end >>a 5o, bo)Xyz')0 bo,5,
b:(25'
anbiho kupla. elamons s a tb

the th n a = (5o, bo)


Ropoang tuplo (50,bo,
Repeition no times 50, 60)

element is a = [s, 63,98)


Hambershup Reluvns
Tue, f
Prexenk in turle otherwise ba a
tn, not n 9 8 not a Falbe
Tetun false.
Returns nua , f all elemants in ay2,3
b: I,2,3
Compori son both tuple. a r e a n e ,
otherwise > True
y a==Eb
reuns false.
12
Returns minimum Yaue un | a: 5,4,0,
mn mn la)
tuple

Returns maci mum Valo i a 5,9, to,


mar
tuple max la)

Retum to)Convert tuplo . tupla ([[o,ao,a0) Cto, 20,30)

tuple upla( he.lo') h,'e'',"',


o')
Dolete the entve tupla > a =5,b,7
dal della

Ba Tupla methnd >st (,45,36)


ndet) Returns tha indat f tRe frst 1
t.ndar 453
madched iten.
SHn inder lob)
Reluvns the Counttha enn = =(5,6,54,5)
Cotunkt) s t . count l5)
elomend
t . Count (o
TELEGRAM: @eduengineering
DAS DEPARTMENT OF
SCIENCE AND HUMANITIES
NeY
Subject Code/Title: Unit:

Tude aGsi gnmet


Tup assignment i a Vory atla che and powelydeaa
in python T altorws tha a shgniiant Valuas to a tula ot lariables
anthe left side the asstg Hment fom the turle Values an the
Sdoe t the asslgnment
hght
The nwnber Variables tha tuple on the
lett of the
Oseignment must matdh
matoh the
he
nurmber o elemenb un ta tupla
the aseignment
onbhe aht of
(25,35,45) t u p : (to, o, 30)
Eg: Ca,b, c)
SS> print la ,b, C)
25 35 45 sprnt (aiy.9)
Lo, 20,30

two numbers tupla as9ignrnen


Swap
> a , b = 7o, b5
>S a,b : b,a

Print ( 'a: ', a, b : ' , 6)


a;bsb
Vavi abla lenth arqument tuples
Tuples as etum vaues
Varaba numer oCqurnent
Tuples can albo e etuvnad by
Taturn Valuoas
Can abo ba pasead to a anci on
the funcion as
procadad an +
unuon returna onyoneA Vauablacolleb
name
onealy tha
tuple a urcon 5tarisk
tha ayqumen ito
han value
"a tuple
Can efurn more one

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

placad ths.do. tha ay bratos . 3 Via


Elamenb in diclionauy a e accoscad kos ard not by thoa
Pos7tion

Tho Values f a dictionauy Con be any data bye.. kouys must

ba m mutable daBo type (numbes Stiras,bupto).


Operalions on dicHanauy
*Acossing on elornant
*pdat

+Add elomant
Mambershup
Exampla
0paradions Doscripu 'no': 123
Creabng a dicionauy
th
S>> a : 5'Namc': 'AAA',
Croating a

dictionary elarneri of difauant daBakypres 2Nama': 'AAA', 'No':1233

alo
tha elomenlh by al'No
Accessg an Accosi ng
123
elemant usinq kep.

Assigning a new to koy


value > af no=b18
, tho old value by >> a
updote at eplacas Mame': 'PAA, 'no :189
new Value
Add nauw eloment nto the a L'AgeJ:18
>a
odd elerrant dicionay wth key
ama' 'AAR, 'o : 16,'oge ';18 j|

Koturns ua ftho koy Proent a 2 Name'; 'AAa, no';bts2|


>Nama' n a
momarShip n dictionau . otheroise
Tne
etuns falbe ge not a
To

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,

Sat dodaul a ='sub: 'Python','Nauks':95 key o the dictionau


kay, value)»y a. got dataut lpopt ', 'Hech') e turns ts Yala, kay
not Present, nsert ke
Print la) value f ditii
'Maks':95, Dept': Na) hvth a

'Sub': Py thon, and r e t u n ditti onauy

ufdaloldd) >y a=f i:bna' Twill add the dicbionay


> b: f : two'j wth the exiskg dicdionai
>a. update Lb)
prntta)
'one', a: two'
ron kaupt key = 'epplo', Mango
Creates a dictionany
0 alue -'fruib'
d : dict. om
D
kep (kay,value) rom Koys and Values.

2'PPpla fnaib", Mango: ruib


cloat) Remove
> a- Narne': "AAA'ge : 18 j Kemove all elomenb
tron he dictionav
a . cloasL)
print ta)
TELEGRAM: @eduengineering
ent) >len (a) a raturng tha. longth
dictionay
dol t ssa= 5'Narme' ' A , 'Pga ";3j Jt wl delele the
del ta) en dactionay

st Comprehensi on

isk Called ist Compra hansion.


Python Suppor Cornputed
ist thto anotha ist
& a toot or transtorming ona

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 ,

LeLo horve for clauses


tor clause then
0r

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

6oY un ao, 40,80]:


[,
,4,J:
L.opperd (i 4y)
Print Ct)
TUushaBre problams

Histo qrams
the Verbica avis
A histo qram shous the roqueney on

and the hongon tal Qxiin dyrantion


anothei ddmantion
create histoqamS usually
Halplst lib Can e lwa b
where eyey n has a m i n i m u m ard maximu
t has bins
n also has a oquoncy tetwoen and vnfinile |
Vaue Each

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

19>)2 (T) 5 Exchange


JEA,
Pint ("Enlau the elomenh ") 812,53,29, 19.
fori Tange lo, n): Pass D i-2

stapperd (int (iput t)) 8 1 3, 19

fUr nange (o, n-) J 3 , 53 >a2(T >Exchange


torj 7ange (it1, n):
v = 3
pas9
temp bt[J 8 1,1 the alues
lT) > Excha oge
5 3 23
1 , 33, 5 3
tI= temp
Sorto Valuos
ao ")
Printe Inseron Sovd
Print } )
n-t npd ('Enla. tho sinye Ls"
oupu
Enla the Sima i s l . 5 ho elernenbs ")
Print (Enlä
Fnle he elomen ranqe lo,n):
lst. apprd Gt lapud ()
1 7 8
Sortad Valuos ae
The for range l,n)
L, 2, 19, 23, 58]

Bampla T,9,12, 19,8 zo ad


lss - J >:EA
tolila
pass: izo the valuos tenp
(T > rchange
63 >2 3
J=1 ,
19, 8 orEj-i] = tep
23 5 3 , alues
Exchange the
23 1 (T) >
2
253, 23, 198 Print ['sortod ist")
Mo changs nts)
2 > 9 ) E)
J 3 EChange
2 >8 lT) >
J , 13
Enlo tha Sinpe s+
8 53, 2 3 , 3248
:27 4
Enla tRa elemer

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 )

J= Print| Total anourd:", total)


21 14 94 8
l ="istui" "chostate" "pen",
pencil'", E v a s e "
27> ) Exchange
8
21 3 2
datail")
21 a 24 8 |Print("pmduct prico
J "bisuuilas,"chocolak
27>0 F) No change uit pYiic :5
27 3t 2 8 o, "pen "; 48,"percil"S|
ase"4
JS, H, a7,3, 9 ,
|34>a4L7) chan9 e Punt luritpvio)
int"prndut
stock detai L
7 4 3,8

J= prd biscui!": Lo, "chowlake *


1 4 lT) &change ailb pen" 28 "penci) ": 5
36 8 > Condikon
4 21
Fase:54
H 24 27 Print lprod )
i u h , n)
378 T xchange Stock de tai u)
441 33b Print ("Curvent
(T) Exchange
Pnnt(pod)
218
|J:3.
34 21 3
Dutpu
Excharge
Procuch Pra detai
T) A8
24>s hocotake : to, pon
J 6 24. 27
36
biscuil: 2s,
(T)
-

Exchange Ponti);8, Enaser


4>8
lock debaib.
a4 21
sb Produ ct 268,
chocolale 8o, fon :
2bisuil : o,
[Ratail b l prcpaualan ponct)58,Era ses:5
Product detais
product deia
V

aef bil) (,n): urcharel


ChocslaBo pen 'ponil'
total o bisuil
Faso
Tolal am ount 19o
Price urutpie delai .

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 :

return tot Shudont [name )


Print
(score) fu B6oesSmend )
studant
de gellottec -qrade prin
)
Score =91: Pnnt (Student ASSIgnment
nttendance.'
veturn o" Prot(studerd fu
Pin "Aeage
mauks ")
refurn n Print(kuma" , e) - letlet-7ade
eh Score="); Gel-avaage lni))))
eturn A*
Pont(Veera: "el-letbe-grade
el SCora >=b1: -aveage ln2))))
e t u r n "B+"

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 -

Punt(class Aveage pde")


vesulb C 7
Pont e lote rade lgel -
class
for Studeo shudons:
avea 3tudon )
rge -aVoLage (sBucent)|
vesul. oppord (7
TELEGRAM: @eduengineering
Oupd
uma
900, q1.0,85-0, 92.0]
Ces.0, 70. 0, 94 DJ
Les.0, q0.0)
Veena
Loo. o
98.o,
Loo.0, 92.0,
8 a . 0 , 83.0, 9).o]

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

ks and aso kaop a opy s the


we want bmodf a
Re Lsf tiself'
The
we
reed t ma ka.atallaN
leto maka
be2 atlo
o copy
atst
tst clohirg.
clohing.
Ongnal This process
tho refeena .
ust
s az 1,2,3,4)
Ceg)
b a[:3]|
[,
Cwith example . Variale efers
Variabe ejers
Loth
oth
3. Define st aiasin9 One Vaia bla b anothe
anothes ,

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-

daleta an ebnen t h a lisl temg


6 Houw Can we
delele one D more
o
del can ba. wa
The kay woyd
he entire s t tself
n a is or
bt 2 ,3,+
log) del stfinder
d e l b+ LaJ
dol t : 1
C,3,41

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','¥

8 write a Python program


to Swap two
Valuos
tupla
a6Signment 85, 5
b- 35

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

under t s tp = l'a 'b' 'e'a'


J tup Count (l'a')
It relurns the under f tke
gven elonent
'e')
E3 tup l'a','b,
tup.tnder lU)

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

Con verS1 on tpcading


hangeD

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

Calls basad on the esultagain.


tha esultagain
methoo Corn puin g
votkes than Cornputing
vesull atke
the renembore d
the

TELEGRAM: @eduengineering
CONNECT WITH US

CONNECT WITH US

WEBSITE: www.eduengineering.net

TELEGRAM: @eduengineering
-

INSTAGRAM: @eduengineering

 Regular Updates for all Semesters


 All Department Notes AVAILABLE
 Handwritten Notes AVAILABLE
 Past Year Question Papers AVAILABLE
 Subject wise Question Banks AVAILABLE
 Important Questions for Semesters AVAILABLE
 Various Author Books AVAILABLE

You might also like