S-Sashna
242|1 A05 JW
PyTHON AS51GNMENT
4. Delin ss. isut about list opoatiens and method.
A t is a buttin data stuc in Python
yow do sto ultiple volues in a
singl varable. iista mudable lmodijiabl
and dent data types
(antaqs, shinqs fioats even othn lusta). Jhey a
the most cemgn n saiabe
and sthing.
ista in aythn uncion similanly to dgnamically
sthur prraming lanquagu, kuh
Awayits n Jausa and Velo n Ct4Bey a
elmet sipaatd
oy cor
Key Jotuns:
i. Ondsud: ists maintan
ms
cü. Hwkoble eu
moditt Susta by adding emeing
hanung elmits
iüi. Auus Duplicat Vals: A st can contain he sounne
iale multipe timus
iw. Hetsanus &emnt: tista
e datoa ('antqus, soinqs, ats euen othu ist
Dynmii Sizu' ists ean ew e shoink dynaically
elmnta a addd
ists vo ditined using sq wane brackuts ( c ) t h
elusts sepana by comn A
dist Opnatisns
ma opuatiens
basie opuLatiens that wan
Pertemd ts
i. nqth ( lun): t..utun he numoe oe elamts
t
num C!, 2,8, 4,5, 13,19)
i. Cancotunatin (+): t menges i t into 4. t ts
a nuo. t athu than modityi ng hu tistin
isti= i, 3, 5]
2 (2,4,6)
istlt it?
t pints C,3,5, 2, 4,6J
i, Ruptition (): 3t peats the clument a list
spatied numb fis.
int -C, 2,3)
psuntl it 2) * poivta ,2,3), 2,3)
iv. Humbeuship Testlin, nst in hks shethr an
he t
in: ns the elmut u pusnt
net in ttunfase tha elum is not prusnt.
ist C10,30,5o,40,40J
prit 30 in ist )
Punt (30 nat in list)
(Ustnd) Jhe elmun n e lint won
V.
Ondiing
Andiing ie
Scono ment hasRnds
nu C!, 2,3,0
Paintl litCi3) pçydu 2
prúvd(atC33)
Negatia nding allous acss
num C10,.20, 30,40J
vi. Sicina ClistCatant step: stup])
Sicing s elemens
Onae fro he gien st. (endhats a potien a iat)
num C,2,3,4,5, 6,4J
tt(2,3 ,4J
print (num :1) t C,,3, 4,5,6,4J)in,
psint (num (u:J)
pxint num?320) tC1, 3, 5, 4)
oint (num -t: -13) t (s,6,4)
vii, 9tatien (fot lsop: Koeps rowgh eachi l m t
list.
num [',2,3)
fon nwwmb n im:
put(nuwm)
Qutput
2
Kut Mthei
4. appendl) Ad van e m n t
humL0, 2o, 30]
uum appund (uo)
prt(ram)E Clo, 20, 30,40l
Hediis the lit in plae ( daent a n it)
iy txtund): Adas multipui
meltipu elimnti
elimnta at the end&st
Stida
Camcaunasien but madites ttu eisting
ist wstiad ualiq
»2,34J
nuum C5,6,)
mum eound (num)
psnt
print (nun) #Et,2,34,5,6,43
an elumut t apucite place
vwn C,3, ]
ruum, insodli, 2 ) tisvt
iv, mel):
Gcurnea vale.
rumm C', 2,3,1,2,3)
num. umae(2)
pint(em) C,3.1,2,3]
V. pepl) Rums an elmnt by indel dufaut last)
the elmnt
t th nd.
n Ci, , 3,4, 5,6]
nm.P&p
Plntlnun t# (1,2,3,4,5]
prnt Cnwm) tt Ci,3 4,5J
vi. cuntl): outs
num =C', 2,l,3,4,1 ,8, ,oJ
pint vum.caunt)
um CI,2,3)
pAint Lnum # C3, 2,1]
viii. clanc): Rumos elment
numz Cl,2,3]
phintlnwum)
2.
Enplain Pythen pestos.
Sn pytnen, oporotons n qnnal pufoun
operaians Nals a d vaniabs.
1 Aithemotie Orsates
i thematie pualons se
Pythan
basie mathemaical opuration ike vaddien
ubthactism, iplication and diision
Rast
Subiats b e (a-b)
Multiplies a nbes
Quotiet ustn a s dioidd
by b Moat)
Rumainder hn a s disidd
b
Qusient wheA sicd
Progham
b= 5
paint ("Aditien o , a tb
paint (" Subtotion e a and b:"
psnt (" ultiplipatisn a*b)
pittl Stislsm:, alb)
pxunt Colulo:, al-5)
utputi
2 Subhatim ek a nd b: 2
35 Mutiplication o a and b:35
Hodul 2
2 Compawion Openaloyi
hee opatos compas h wales 6 eitt stuns
Tue Co) talu acconing to He couditin
Openats Resut
valu
qotud Rhan H sesn.
the
values qruatit haw bst
Relin Gue betth vals
Ritus tu i kt valus
quat fha ohe equal te secsnd.
eual to second.
13
b=33
psuntlsb)
print (acb)
psi t (a>xb)
print (a!b)
prnt (a b)
pint lac=)
Qutput:
Bale
Te
Tue
tale
eaical Openato -
Pytn sqical spates porlom koqical AD,
Dqieal OR, Leeal NOTopatiens. 9t s used to
cembine condit'nal stoment.
NOT
G Zoqieal
Prognam:
P l t (a andb)
print st a)
Otputi
Tue
talse
and
Sik- by-bit operas. he
yunbes.
he Bitusi epehate
AND
i) Bitui oR
(iy Bitusise XOR
NOT
Prsqami
b 4
pint(aeb)
print lalb)
pint (a^b)
print (as
prunt (a<<)
Skput
5. Aasiomenl Qpenalei
The pythen
asin vals
Assioand eperato a
Hhe vaials
vol
eperand
bea
print(6)
b+=a
Pantl6)
printlo)
bt2 a
prnttb)
bt< a
pntcb)
Output:
20
I0240o
6. 3dnty pratss
Pythen, is
t themuey 2
vahiabls khat
equal dont inly (Bhat
Lahe idtical.
Tue
not idntial
Phoaanm:
aAo
b 20
Phint ( a not b)
Qutput
Tsu
Tsu
Qnd net n al mmbip epala uslh
shethn vaue variable
Tue value found
tound
Peram:
Saiana
paint.s in a)
Print ('s
Sutput
Tu
3Wit n conseuis
Jmplit type cawwsieni
autemotieall
N2o
typ(s)
Ayp got autematicalt chanqud
nplicil_ ty Conuesi on:
data type manwaly elhangd hy
p
Pnt (a,bau: Ceet data bp
Hoatl Cout data t pe Foating padut umbe
ordey Cowt charoctr to iniq
henl: Coet Ai -to hnadciwal ntiyu
ot): CawtT
(tg to odtal atung
bupl e: Couet totuph
Autty: Coet ti At
duet: C o t
aciCoet wti to tinq
cu Coet ntu to Ascu haoetu
Preghamn
Sy'
ba eat. (a)
Print(b)
pi nt(c
print (c)
psintlc
9tput:
00
5
Ox38
Wu abet kamoda fntiens
Pthon uneyms tncte
wthout
kutind wina lamhda kuyoond.
ao calld lanbda tunetis.
uc map)
Syntan: Janda [anqeunt (s)]: enpwisn
canditisn
emt bad
with
he
’Taks hnction ond a wtaable sbject
nm C',2,3, 4, 5,6,1, 8,4,103
Qutput Cz,4,6,s ,i0
Appies a tunctrion
Supntan: map( fun, iahlu)
pÀnt (sgyan)
Qutput: C,4,4,ib,53
apply a tuneti'n ulally to elumenti
a ocumlatd t
tuncsols
Jmpout heduee
um æs3, S,6,1,8,A,l0]
Sutput Ss
5. Wsiut abeut stn opuatins
8fhings a a squnce Rttu
and pacs
pyh sing ean be almet ay luvoth
bpace
They a asiqmo ina
Sting Operatiosi
tut
b weld'
print(c)
Qutput hulloused
W): Concalnas
thing:
Prognam
phint (ey
i) hduxing and slicinq!
a chahactu
adiina
sting oaud on
Siclng porkin
taing
Sahina
Salna
Sahi
(iv) Munbeship:
nat
tur
stina,
a = Agthon'
epint(''
Pint ('t' n a)
tut eugh Hhe
sing'
arSahiahna
phint (iam)