You are on page 1of 25

22Wednesday

APRIL 112 253 We 17

ist1:insert l, 50)
print(list1)

elp:Hello, 50, 1)2,love, Raju pamu


Rst 1C1:11- C loo"," 120,1401
pxint (list 1)

olp:- Hello,'joo,l2o, 'uol, Se, 1,2, "lue, Raju',


Ramu

+Delele/ Remove st items

Dse del keyusord


del list dellist[1:3]

del list111
Print Clist1)
olp:-[Hello,'2o 1Mo, 5o, 1,, lovel, leaju, tam
del list
pYint istd1)

P:-

2009
Week 17 113-252
23Thursday
APRIL
16

06
Yemove item) uSed to ycmove an idem rom he
09
Pop Cinder) ; xemove and re turnS ite ts
a t Spocified nder
Ppoemove and etumns last item xom the
10

list1=["Laya" a"b ,1,2


printfxiendS, Yemove( " b)

13
lp-Laya','al,'e,1,2]
print list4:pop))
o]p:-2
Phint llise 1 popl 2))

clear a list

clcar )

2009
24 Friday
APRIL

Tuple

mder Colleclion. o Hems


I m m y t a b l e

Allouws duplicate idem


7
L).to qreup
elemen ts
use parên-Lhesis
Creating
27,64)
mauks= Ro,50, 80,
pintltype.Lmarks)

lpclass tupl
Oobther ple
2me Tuple inside uplesmutidimensiong
Tis knDuon asnesHed
tup les Ganga
Giends=( laya", kaviyaLatha
prinEl maYk[o])
print[fiends [oJ)

Laya
without Paverhesis
Cyeated
Tuples Can aso le
20, 50,f0, 11,67
marks
typelmayks)

opeuple
2009
Week 17 115-250
25 Saturday
APRIL
mayks = 6 o , t 6 o ) mayks= 6o,
Print type (maks)) print type Cmayk s)
oP<clasint plp2last'tuplels
Accessing tuple elementS
Tndex Enoy Tnder is out Yange
ype Eaox (Tf 19-08 inSteadoe 1a)
Elements ef a
tuple aan be
they ave assign ed but 1 changed e
isa murta bldata he elements itse
ype like lis E, Hen it can
15 bechanged
2
ieds=l' Layakavya [20,30, 4o, 50])
iends[2JLbj=9o
PxIntriends)
olp
Laya kavyaL10, 30, 40,501)
Deleking a tuple J

ue can delete
entive uple using del keyuwor d:

2009
26 sur
APRIL 116-249 Week 17

Conve-ing a list to tuple

Conveyteto unle
1st can be
kupleLlisE

Ruf-in mehods

index( Value)- Rekuns indez ofhe given value


Count(Value)- Rewns
the equency OCCance
a Specified vaue

Euple =4,8,5,1,1,1,4,5, 8,D,9,7, 5,6, 2)


uple index )

op3
tuple Count(5)
3

Boolean
TROEFALSE
Stato aSSigo CY COmpaxe boo lean values

SebScribed True
print (type(Subscibed ))
dollouwed = false
Pint ltype lfolloue))
OP clasc boo 2009
cdassool
Week 18 117-248
27 Monday
APRIL
08
a loo
39
blo0
printla- b)

opTue
printCboolla)
o/pTrue
bo

printl boolLb)
olpifalse
Set
Undexed Collection of items
Mutable
Doesn E allous duplicate item slevery element is u

bGeating a et
18
1f-Cunly brace s
ouiHin Selts tuncion
Can have any
no of HemS and heq may be
diffexent types
be

anchor5 Udayana banu gaTu,"Sumo


2009 Sudheeyanna prodeep anna akka
Rav' a"
29
28Tuesday
APRIL 118-247 Week 18

pxict lty pe.lanchovs ))


o]Ptaeclass lsel
Aou-to Ceae an enmpky set?
Empty list- 0
Empty Set-s set0

empeyset={?_ emptySet Seb)


peintlbypelemplyset ) Print Ctype lemptySeE ))
oP class aict olp: eclass'set'
Sel 1,2,3,u,4
printlsetDLn
olp-{1,2,3, a
Atcessingelementa from sel
Since they ave unordev ed,we cant indexing/STlicing
e Can itevate oveY se using loops

Add/upda-e
Odid) meth s_uced lo add Single elementto the
Sel
upalatet) methad is used to ado mul tiple elements
IEcan take tuple s, list, serings ox ther se as2009
avgeonents.
29 wednesday
APRIL

a12,3,4, 5} a1,3,5,,5f
print la) printta)
a addl6)
a updatelL6,1,8,11)
printta) print (a)

o)p-f1,2,3, 4, 5t olP:-1, 3,3,4,s


1,2,3,4,5,63 4),2, 3, 4, S,,=
12

Removing
aiscard(ttem) Speciied item will be vembued
14 he Se
Yemovelitevm) )
a1,2,3,4,5} 0-1,2,3,13
printta) Q discard [5)
olp:-f1,2,3,f
op-{1,3,1, aYempNel5)_
17
adiscavd (4) p-keyEnor55
18
print la)
ofP 1123, 5
aYemove tt)
printla)
op2,3,5
pop)
Remoe k velunsan item
2009
row what Hem15 homhe sel. You neve
geingo bePopped up
30 Thursday
APRIL 120 245 Week 18

set{1,5,3,8,1,
Set pop)
printIseE)

olp3,H5,8,1

Cleay

lo Yemove all+he 1fems om-he set

setf1,5,3, 8,1,4
Set clea)
Printlset)

OP-Sett)

Set operationS
unioo, intexsechion dilfevence, Sqmmebicdi fferente

UnionSet of allhe elements from both -he sels

a 10 20, 30,uo
b20,o, fo,ico f
abUnion = a b Cor) union(b)

pintlabUnion)
op:-10,20, 30, 40, 89,Fo,toof2
2009
Wiek 18 121-244
Friday
MAY
inte sechion: Sel of elemenks that ave Commne
ho-lh -Ihesels
Set1-f, 2,3, tu, 5{
Sel f9,8,1,4,6 f
print (Set 1. intevsection (set 2) (o1)
printlsel 1&
"elp:- u
diPlevence a-b (set of elermentsthat ave
only ina
but not in 6)

Setf-f1,2,3,",5f
Set 29, F, 1,4,6
print Cgetrd iflexence (Sel 2)) tor) print (sel1-Set 2)
b
plp- 2,3, 5}
SymmetiC diffeventeof a and b is
Se of a

clem@nds in aland bhutnot in


Set4,2,3,41,5}
Sets-f9,8,2,h,6
printlsel4- Symmetvic dliffeence lb) to print (Sel1
P12,2,5,1,92,6
iniauIut

2009
Saturday
MAY 122-243 Week 18

s o 2 e ns e l s

mLelable Vesion
of set
Elemen
nEs 0 fozen set remainS Same after Creation

DiChonay

UncdeYed colleckion of ilenc


+Matable

holds key:alue pair instend of single eleneot


hke other data ty pes

Cveating dictionay
Dictfonavies can be cveated by placing elements
insidleftuly braces
Cuptax 2 riends 1 key i Value, keq: value,keyivale?
4 tales Can be of any ype lavd can be duplicaked
whexe as keys canbe vepeaLed duplicete
keys mustbe unigue and mus be immutable like
1skipg number, D1 a kuple with immutable_elenents)
ue an also use dicti to creakea dickionay

btobatafname": Suesh"acdress "pavala''


"Gubsoibed: Tuej
eypelbiopata)
class olic t>
sttd Dictionaiy PEC
cating a dictienary inside a dickionauy is calla
hested dic tionayy 2009
Wee 18 12s32
3 Sunday
MAY

nestelDica fr:me' 2:20wendy HO ou


-key willraise if-he key iSnot
evror

geED-etunS NoneIthe key 1Snot found.oiutna


print lbio Data"name")
p-Saxech
print(bio Data.gek rame ))
Olp:-Sunesh
my.
dicE-1,2:u,3:9,4216,
print Cmy-dict [5]J[91) S:26:36,:19, e:6u.,1:Ri

Ringpdating aielionary elements


1

a-L:L,2:432,
a lHj- o
4al6, 5:2s
Print la)
a l103- 1oo
printla)

P:-f1:1,8:4 3:1,:10, S:T?


2 SL:1, :4,3:9, 4! 10,
2009 S:aS, lo loof :
A
4Monday
MAY
124-241 Wek19
Remavin Clements

del dictionaYy Ckey


popCkey
popitem)
clear)

ue can tven
Cxeate our Own data type

y)Con-terolows
x Contyolflou Sta-ern@ntS e Very
huild Complex and pevformant
impor-.aro
Pograms In aoy
language
(t) T

Condition
tstatements to exeule
eglastBal) -6 astBall-4
last Balle-6: 1f lastBall:6
Print(uwon the match Print'uon)
elses
o P

p-LwOn he malch

2009
Week 19 125-240
MAY
Tuesday
Cti else
9

ifCCond-kon)
Executes if dock
else
#Exetutes_else block
letsride
12
iSeYen
a ram to check uwhe4 a numbe
oy Odd
13
nambeY= intlinput CEnter
1f numbey ==o)
a numbey )

else
printIE iS even
numker
PrintI is dd Qumber)
1 lp Entey a number 10o
It is euen numbey
ntey a umeY 23
I i s odd number
Ct)Nested iP
Iinside anothe
(i) H-elif Jaddev
2009
OWednesday
MAY 126-239 Week 19

Caonk =int linput Enter rank "))


Yankk jo00)
print("college 1)
eliFlT60o okankk Ioooo) and
print(Co!lege a)
elie16 ooo ran Hoo 00) & and
pvint Coll ege 3)
else
printl Soy nocolleges availblle fo you vank

Shonlhand i

statements ue can use dovthand


for single
Dperatio n

xe20: intCreater) Pqeater

Shothard ifelse_
StatementIf_True if condition else statemenk tfpafe

u/,2= 2o) else pvint(odd)


printC eved) if
2009
Week 19 129-236 O Saturday
MAY
(v) fox loap R
Any equenCe hich you Can terale
caled iterable oLer IS

x-lisE,tuple, string etc-


YangeiUsed ogenexateSequente o numbere
ange(staxt, stop, step)
>>>printlyange lto))
range Lo, 1o)
9>> prntlrangelm)

yangeCo,) 0le P
1used tor Seguen-ial avercing.
pixednoo 1leva-ionS (olelintte
Vavin 1terable
Skatem Cnts
The Vay lakes the value of next tem om e
iterable each time thxough the
loop

2009
10
MAY
Sunday
130 235 Week 19

Lerslist =CL,2,3,10, 19,3


fox numbev innumbeyslist :
printlnumbev)

50

oYa nange lio)


Printl5 number)
eIp-D

15
20
5
30
3)
HO
45

2009
11 Monday
MAY
W e e 2 0 131-234

Snech
for in Yange (o,5):
name print.4i)'
f o x i n name

pint

olp:-S

Foy ench idem in Sequen


ce

LOSc Come aut o lo0p

False

StatementS

hame inpatl Enter yy ame )


a name [-2J
P
t In Yange
1,1),
printla *)

Dlp ntey qour name Laya


Ja
aya
yaga
2009
gayaya
2728
2
12 Tuesday
MAY 132-233 Week 20

p h y a y a l y a

y a y a a y a y a

yayayaya ya

yayayayayaya

ya yaya a p yaya
y ya yayagay4ya ya
ua ya gaAGA YAga ya A ya

pind vowels and ConSonant in you nameZ


namee inputl Ete youy name )
voLielslist a , e o u']
ox charactey inname
if Charackey in VouelsList;
paint(chaxacker t is vowel)
else:
pxint (chavacter, Tt is Contsant

opEntey your name: laya


Lis ConSonant
a isVo el
y is Consohant
a ivowel
Find ybuxname bas a voLcel_in your name
ue have to Contro loop

2009
Wes 20 1332 MAY Wednesday
lo o Corol loop

Con-o slatemems
beak
Coo-inue
paSS
eak ; ReturnS Contol out of he
ConcinueRetuvnS Con Erol tothe loap direl
loo
pass Dsed as a placeholder f utuve
beainning
tation of loopt unctions etc lenet
hame=input Ente yobtr nanme
vowelslisE-[la,le;
fOY
u1
chaxoa cter in name l
FchraCte in VowelslisSt
pinE Lohanactev,TE is vowel)
break
8
olp Ente youY home 2 Loga
a-TE1S Vouwel

2009
14Thursday
MAY 134-231 Week 20

hurmberS 4: one 2: two 3: thvee'?


oY i n num kerS
Print t)
Continue break
pintLhumbers Cia)
olp.
plp:-1
2

Pass

+Used as a placeholdey fex future implementation


f loopunctioos etc
Interpretey ill ignoe a tomment whereas pas
ofil no be ignoved
Houoever,modhing happens wben he pass exeutts

PavkS=[45,98,11,92,161 markS= [9s,18, 91,12,96]


tor in mavks
PrintCSum lmarks )) zor i in markS:
beak Sum-Sum+i
PrintLSum
Dlp-9 olp472

2009
MAY16saturday
) while loo
ndefinile Herartfon
Lohile ex preSsion
boay f he loop

uckile loop slas


False Come oct
bop
True
statenents

nBook Cricket
while (i 41: Consider pu hae a book
o 3o pagfs
print li plip the book ill you get Soo
it=l print al he Values (ScYoes)
prlnt no: filpc ta ken-o
olp:- Com plele the Sco SCeYe
2

2009
Wesk 20 137228
17 Sunday
MAY

impot andam
9
print (random.randint 1, 30)
Scoxe O
SCOveTnfo
whileScoxe 500
random. Yaain Ell,30)ScoYe Va lue
11
ScoYe Scoret ScpYe Value
print(Scovva ueyendGcove Value)

Lm port Yandom
SCoYeO
ScoYeTnfo= [1
Luhile S CoYe 5000
SoYe Va lue Yandomandint3o)
Scove SCove + SCove
Value
16
ScoxeInfo:append Cre value)
printtTolal plips len (Scove Iofo), StoveInfo) Score)

2009
MAYMonday 138-227 Week 21

6DifHevence bJ list and tuple


List Tuple
LISeS SguaYe brackels Dses brackets
[lD, 20,3o1 Llo,20,2o)
Mutable Tmmutable
sloue Fastey

Etplain Hernaryoperatov i n py-hon

onErue 1if [eapresionl else Ion false]

Remave duplicate elemends froma list


Convert ist to set

Set ltst)

2009
Week 21
19 Tuesday
MAY
139 226

16) Funchons:
Sumar
P
ce tuntiooName(paxame terS)
Statements

YiHea ogram o check whethev 19, 18, 2


even bY Ddd Urthout function a
3

humber1-19
4
nLUm ber218 n Lat
Durmber3-22
number1 lo F0)
print[ s eve Ormat (number 1)
else )_
print 3 i daoYmat (humber
1F (number2 2= =0) 1))
17

pint
'
is even fomat lnunmbera)
elge
Pint C 1s
number 3 = oddomat
=o) CnurckerD).
pint Seventogal
else (number 3)
print is bld
furmaElnumber 3)
olp 1q is dd
8 1S eVen
2009
dd IS elen

You might also like