0% found this document useful (0 votes)
18 views13 pages

Adobe Scan 12 Nov 2024

Uploaded by

Rehan Pasha
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)
18 views13 pages

Adobe Scan 12 Nov 2024

Uploaded by

Rehan Pasha
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/ 13

INTRODUCTION TO PYTHON PROGRAMMING BPLCK105/205B

modne T:

List s:
stred in tthe ist
o The Sesutne d Valhes. be ales
List is a
Ae caed items. be valnes ts tthe Gst an be integets, fboal,
SRings ete.
i:0t [lo,2o, 3o,ho,so
Onames L"abc","yz'", "pa'

Ibe valns stoaed in the list ae accessed ing jndex.


be inder stats m'o!
? t Llo, 20,30,4o,S

e cay alSo wse e index. Be index Teters to the last


Vde in tbe Ust. te de -2 efers t 2h last valn amg
So e .
Eg: t o , 2)3o, 4o]

List slieing! be poaion & the ist or segment d7dy the st


is caled sice. Folloing syntax is wed tol sicing the st.
ist_namesast: end: step-valu
Syrtas:
" (be above nethad wsll poovice a sliced tist stating fro
i t a t Qocatioy to "end" Locatioy ith as in CÝe men o
stepvalne".
state im
i6 the stat valne is hot presen, the shcg
begsning ds the ist amd it tbe "end" Valne is hot present
the slrcin be defan
takec plele tll end q the list. the
ale k the step_vae" is .

DR. UMESH D. DIXIT, DEPARTMENT OF ECE, BLDEACET, VIJAYAPUR


INTRODUCTION TO PYTHON PROGRAMMING-BPLCK105/205B

t[:s]= [2o, 30,4o, <D) )tlo:5:2) Cio, 3o.53)


t[:3]: [io,3, 30]

Lict Concad enatien and Replicadies:


operato is set to Cohcaenate t s lists It l
" lhe
Combine tur ite and creale a new ist
t : Cio,20,30]

Outpt: 1o, 20, 30, ho,so, 60]


opeato ic wed to Aeplicoate te st valnu sth
The *
no. d times.
ti:lo ,20,30] x3
pontct)
OutptLo,2o, 30, 10, 20,30, (o, D0, 30

'tello.
INTRODUCTION TOPYTHON PROGRAMMING BPLCK105/205B

Lists cnd fundions:


O lenc): he encsfunt ion ic wed to frd lengtb os tte
ist, Tt etuns no. elements stored iy tthe list.
Z4! t>Llo,20,30,4o]
leslt) 4.
sum): 1bis functio is used to fnd Suy of values
Stored iy be ust. It can be ued ohy if the ld contaiys
humbers
g! ti,2,3;4s

etns masmuw Value o


3) axC): be maL) fun chioy
ates, it ed uans tte
(be list. 1f te ist Contains choar
characte sth highest Asci Valne.
15
' 0 tLlo, 25, S, 30,
maxlt) ’ 30

t#',e,,U,'o]

minl): be mincy Tuntroh is wed to lowest vauc d


charaterS, it etnns
e Rist. 1 t e ist contains
te chaate ith owest AsCI Value.
2]
: 0 tL10, S, 20,
minlt)

nint)'e!

DR. UMESH D. DIXIT, DEPARTMENT OF ECE, BLDEACET, VIJAYAPUR


INTRODUCTION TO PYTHON PROGRAMMING BPLCK105/205B

del eptoj.:
be del epeatos is whed to delete n elenentCVal) sing He
index.
t Cio, 20,30,4o, S]
del t J
pont Ct)
Qtput! 0,30, 4o,so
Pn and not in opeato s:
is hsed to check, ohehe a Valhe exist in
eperdo
tbe list or not. Tt setnsns ue ib the valhe ist, oftbesst
Rctnss blse.
i4:0t-o, 2a, 30, he, so] tt Llo,20,3o,40S
SD in t 200 vgot in t
Resut false.
Resnt: Trne
eperatos vens tru, it the speibied Value
Tbe not în balse.
doesnot est n the lEG!, Ottewise ít r e t s
g:0t L'cat", "doq", "CorJ
cow" not îb t

Rect: false
"elephant" notint
Rest True.

LIST METHODSi Tbe med hods e Sinnila to tun tions. ßut


the methody need to be sed noth obje cts o pastkcnla type.
opertor is sed to acce s tbe yethods.
15e
O inden (): 1bis melhod is sed fnd index a paicna
Vadne in the tist. 4 mntiple Valns exicd is the ict,
the jncec) method retns index dA the host alte
the valne does not eict, pvodu(es
DR. UMESH D. DIXIT, DEPARTMENT OF ECE, BLDEACET, VIUAYAPUR
INTRODUCTION TO PYTHON PROGRAMMING - BPLCK105/205B
tLlo,1e, 30, 401cD
1. inde (30)

app.end); bis mdhod is Wed to atd a "Valne ib he


isd. be bew Vale is added a th Chd d the ict
2G!t L1o, 3o,3o)
t.apped (luo)
pointct)
Resnt! L10,20,3o, 4o

Be nset medhod is used to add the


Valne' in
3) inset):
Speibic positien or indey

t. inserCI, to0) +insets (o at ihcde|


peintct)
Besult (oo,o, J0,30,4o
valne foo
(4)emovec): Bs medhod ic ned to zemove tthe
the ist.
t= Clo, 20,30,4o, SU
t.reove (u)
posnt (t)
Besut: Llo) 20,30,5o]
(5is ethod is wed t eove a Vale rO
pepco :
its den.
e list sig
t- pop)
pint(t)
Result: lo, 20,4o)
DR. UMESH D. DIXIT, DEPARTMENT OF ECE, BLDEACET, VIJAYAPUR
INTRODUCTION TO PYTHON PROGRAMMING - BPLCK105/205B

( soxt): T5e Sopte medhod is wed to alamge be


Values s0ved iy the ist in n aScending ovdes
* Tt ohs it the lact contains
um bers amd
ohings
order amd
* 1be humbers oe aanged iy ascendig
based on
Sings aÂt aramged in alphabetscal orde
Asct Vaues.
! 0 t l 2o , to,36, 15)
t.Sortc)
pönt (t)
Ontput L10,20,3o, hol

t-sortcy
Ortpnt: [Cat","co'", dg'elpht]
Matiple AMgnngent
ent allons t assgn Values o a ist to
15e mdiple aysns line d Code.
mudiple valiebles in a
t Lio,20 ,30]
R, b, c t c=3o,
al0, b-2o Cond
T5e above exarple ill asigs
|ALgment edl asegnot epoatoys;
Sum- sum+i- Sumti
faetfodyi frts=i

DR. UMESH D. DIXIT, DEPARTMENT OF ECE, BLDEACET, VIJAYAPUR


INTRODUCTION TO PYTHON PROGRAMMING BPLCK105/205B

Malable and Tmmtable Datdpel '


) L+st: List is a matable dataty pe. It allows t add,cang
and to demove Valns fooy the liss.
t Lio, 0, 301

prsnt ct)
Ontp!lo4o,3o

ng5 aes y utable. It s not possble ho


9stsngs: stoAd in a stasng. ny attept
change tbe`chaate'
chang ledt a tng wsll prdn e esis me sage.
tet ad Concatenate the stinga to
B t e Ca slice
bild a
S): "Great
Eror.

S2: SP1+'a'+ s : I
pränt Csa) Geat
ale sinila to t , b except ways
) Tapleg: Tnples
* Frste tples
t (10, 20,3o,
jnynable. The cohtentssed
Sacondly, tples ahe
tuple Comnot be chawged.
the 4o)
:t= Clo, 2o, 30,
t J - (00

VIJAYAPUR
DR. UMESH D. DIXIT, DEPARTMENT OF ECE, BLDEACET,
INTRODUcTION TOPYTHON PROGRAMMING- BPLCK105/2058

The list ) and tgle) funchons


x Listc) - The tistofunchoy ic wsed to (ouvet o teple
in to ust.
E t (io, 28, 30)
ti ist ()
pnt Ct)
Dntput [lo,2e,3o4

lict to tpk.
s: t= Cto,20,30)
tie tupleCt)
prövt (ti)
Otpt: C1o, 0, 30)

owd dap(y fundons


mod

VMAYAPUR
DR. UMl SH0 DIXIT, OPAR TME NI OF t I 8iDEACET
UAYAPUR BLDEACET, DEPARTMENT
ECE, OF DIXIT, UMESH
D. DR.
(oldList) prist
llo)-'AA' od.list
deopopyold
_ist) Copy benict
20, [to, Lst old
Sv,
6o] 30].[4o, copy import
isd and
etly imodifed becay deshhtsen
List.
list. a objc
ds (he
the bot Honce
liot sowlie Copy oslCopy)
l deep Hooeves,
lin
ks
a Sepeate
bo]] ['An',
sv, 3o).|to,2e,
lo,20,3o),['AA',
sD,60]| cle:
llotd_bc)
tdlist) Copy
(o lo'y
BPLCK105/205B PROGRAMMING- PYTHONINTRODUCTION
TO
INTRODUCTION TO PYTHON PROGRAMMING - BPLCK105/205B

1 NFunction to compute factorial


2 def fact()
fact=1
lor iinrangr(1,n+1,1)
fact=fact*i
return fact

8 #Man program to compute npr


ad ner
9 n-intinputi'Enter n))
10 zint(nput('Enter r="))
11 ngr=fact(n) factn r)
12 ncr-fact(n)/(fact(n-r)*fact(r))
13 print(NPR=npr)
14 printNCR-'nc)

1 #To compute mean, SD and


variance.
2 import math
3 I=list()
4 n=int(input('Enter the list length
=))
5 for iin range(0,n):
x-int(input('Enter the lement =)
7 L.append(x)

9 sum=sum(0)
10 mean sum/n

1? sqsum 0
13 fori in tange(0,n)
14 sqsum sq5un0l}mean))

1 Variancessqsum/n
1/sdmath sqt(vaiance)

19 print('Mean-mean)
pont(Vorlance ,vatance)
21 print('Standard Deviation=sd)
INTRODUCTION TO PYTHON PROGRAMMING BPLCK105/205B

1he Didionay Dtatype:


olle tio ValQ. e ibdex in dicion aie
Dictionag iS
ned not to be an inteser,
inteser,it can be ot ay datatype.
it can
Tbe indea wsed in the dcion oy
iy c
iC cal eo"key'rd
and

the key with its asso Ciated vdce is called key-value"


pai Uales
be dicionay valnes oe sto red
stored ying braces }
j' bith days ='abc':'June i', 'pqr': "Aug 5, g:J5
be above example stores baues keys and birttdags a
Values also be wed to chech nhethea
" Tbe in and not in eperators can
Isey o Valne exst in dici onyo not Methodsi
itemsc)

beysc method is nsed to access the key Ualnes stored

dictionay 'ayz: Jan 5


birth day:'abc': 'June t', pqr';'Aug5',
fo k in biattdayskeysc):
printCk)
Otpt abc
P4

etns tte vaues ascoliate l f i


T5e Ualnsc) yetho
hey i5 abiothdags-abe':
didioy
Juret, p9':
hg.y':ai
vin bio tlyd<. aluesc ):
for p n t )
Output: TuneI

Jans

DR. UMESH D. DIXIT, DEPARTMENT OF ECE, BLDEACET, VIJAYAPUR


INTRODUCTION TO PYTHON PRoGRAMMING- BPLCK105/205B

be itens) methad is ed to obtain botb heys and


,
Valaes shoyed ih a lst,
:abc':! Jure i', pgr: hug S','ge:Ja
ig: birthdays items():
p kvin bisthdays.
print (k,v)

bes fuocto mehod retuins the Vale


methedi
he qet) boith
nted a patic lan key
assoo a
dictionay-hame.qetCkey Nal
Synt: aguments.
tuD
Tbe at methed takes
hose Valu is It is optional.
* be bey' nane
na be bey does not exist.
to rets
* Tbe"Valne"
Junei','par:'Aug 5
'abc:
ig 0bisthdays
print(birth days getl'abe','seftio'))
olp: Jwne l
'seplie'))
pintCbirttydays get('y',
olpi Septio .
Ibe setdfaulto Method; assigya a defant
valu
setdefautco mthad is wed to
be doesnot exist
the key
|to key,if
Syntax: dictonay-hanmekey, Valne)
$'abe':'June 1','pgr': "Aug
l'abe','Sept lo') ’ olp: June l
birthdays. Setdefau
pgr':'Aug
print Cbirthdys) olp:?'abc': June l',
SetdefakC"ay,'sept1o')
biotbdays
'y':se't
print(birthdayo) olp:'abe':'urne l,'rq:'nug',

VIJAYAPUR
DEPARTMENT OF ECE, BLDEACET,
DR. UMESH D. DIXIT,
INTRODUCTION TO PYTHON PROGRAMMING- BPLCK105/205tB
k te a prngram to cont frea o alphabets in a qren

#7o
To cownt frag uency alphabts
str inpat ('Enter a staing =)
d=dictc
for ch in st:
d[b]- dgetCch,o) +1
pnntcd)

diqt humber (as dass) fooy the console Develp


Read a mlti
phegr to digt with sutable
print the freq do cadhdat

sh= input ('Entey the npt=)

fo c in str:
dTcbJ - diqet(c,o) +1
V+lties)
prntl Ibe dit'+ 7+'appeas'
E: Enter t e ibp; SIS6G3
cigt Ippeas 3 tinscs
|5e digt
digit S appeas 2 timy
tbe dGt 2 ppeahs times
e digst 6 apPeans timeg.
the digit 3 ppes tise

seads dsats Dnglish wrds and


* Nite a pregiam that
Kannata wod.
Convete bemn into
Hint: d- 'one :'Ondu', 'toiEradu', hree'; yoo
DR. UMESH D. DIXIT, DEPARTMENT OF ECE, BLDEACET, VIJAYAPUR

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy