Professional Documents
Culture Documents
net
ww
w.E
asy
E ngi
nee
rin
g.n
et
ww
w .Ea
syE
ngi
n eer
i ng.
net
ww
w.E
asy
E ngi
nee
rin
g.n
et
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
asy
E ngi
nee
rin
g.n
et
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
asy
E ngi
nee
ri ng.
n et
ww
w .Ea
syE
ngi
nee
rin
g .ne
t
ww
w.E
asy
E ngi
nee
r ing
.ne
t
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w .Ea
syE
ngi
nee
rin
g .ne
t
ww
w.E
asy
En
gin
ee rin
g.n
et
ww
w .Ea
syE
ngi
nee
rin
g.n
et
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w .Ea
syE
ngi
nee
rin
g .ne
t
ww
w .Ea
syE
ngi
n eer
i ng.
net
ww
w .Ea
syE
ngi
nee
rin
g.n
et
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
asy
E ngi
n eer
i ng.
net
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
asy
E ngi
n eer
i ng.
ne t
ww
w.E
asy
E ngi
n eer
i ng.
net
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w .Ea
syE
ngi
nee
rin
g.n
et
ww
w.E
asy
E ngi
nee
rin
g.n
e t
MENTS
UNIT T DATA THPESFPRESS)ONvs, STnTE
Problem
ww python
Applcaloms
u
solving Vauiou nginaering problama
Tntroducton
w.Ec by t Python
veleped bjuido Van Rossum duing 1985-
a
Pythen
s y
was
En
a
1990Pthan level
languaqo.
Proqramming larguago
hih
oñented and
object
Rython is gi
intexpraed
at run nebye
tima the tes preter. So
Rrthon is processed
there is ho need to Compile. a Progam riexecul
before
ng.
ing t.
Python is
Proqrams
Tntaactivn
Python
and
woT
k
da bu9ging
un Tnteactive
a
ne
ocode.
plows
mae. which
t
allows
otacive testing
Easy to loarn
is ceary dofned
and easily readable
A Python Proqram
s Vey sumpla.
|The trcture. of. tho Prog a m
Vorsatla.
.
Cada.
Python
lang uage
.Ehigh
asydavelop
thaB
a
Ubed b
lovel genoca
a
Purpose2 Programming
En
including nage Processi
ncuding n9, tex procaseng
and numeric data fom
netxork.
gin
lovel apk caftons uing Sientife
Embaddod Siptiqlarg
3D software eer
veb peve lopmont
Python t an easy exBensibla
in Ranguage
g.n tha
Imago procass'ing
ScieNtfic and cornputalional applicaluons
*Ujamas
Ente prise and business applicalions.
Opovating Systom S.
anguuaga deelp mant
Netuwort Programming ard Prvto typing.
Download From: www.EasyEngineering.net
FSNUA
NEOey
DEPARTMENT OF
SCIENCE AND HUMANITIES
Subject Code/Title:
Download From: www.EasyEngineering.net Unit:
Python- TntapreBe.
Inte pralea
To execute a Proq v a m
n a highlevel Languega
rons la ting One line at a time is calladtntes Ppraleu.
Comslos high lavel Language
To translate a Pogram wntten
a
Inteproter
pro cassing
Compilo
w.E
Pre asy Pre
soutput
En
Pocassing CompiloProassnMachino
Souco
Code Codo
and gin
Inteuprate
DHouona batwaen
Comples
eer
TNTER PRETER
CoM PILER
entire
Program Translatas ing program one
Compila Scans tha
language t coda ü
No Tnkesmediake objeck
Tnkamediata ojeck code a Geneatad Generaled.
statemanis aua
Condibonal control stataments ad
Cond:honal Control
executes Slowe.
Ereutes faske.
ww Tnteacdive
*ScripE moda .
moda
Nosing in
un nteiactre mada. Convenient jos beginnars
and for tosting Small Codes:
D1SADYPN TAYE
We Cannot Gare. the Satemenb and hare to' relipe all
tha Staleman Onca again to Te-Tun them
Script moda.
Tn Scrip modo , type python Proqpam n a l e ard store
the le with
wth Py
P ExtonSion and use the Unteprelos lo execude
the contanb of the Jle , which b callad a eript
the
does not aukornalically diplay rosulb.
ython Seript mode.
uwill use tha
the
In ordes to cea oulput Jrom a
python Seript, we
w.E
b
a 25
9
C = atFb
asy
Pint(sun;"c)
En
Otp
Sum 16 gin
Difeono betwcon Intesacti ad Sipt eer moda
Aua
A uay using tha- python .ne
A A way u i n g tha python
Intepretes by typing
sBaemensdnteprele toed
statomerb tn a Snpt.
t ard execute
Pompt
codaCan Sare ad edit tha Code.
Cannot Sara ard edil the
the esulb
We cannot sec
We anSeo the yosults
tnmedialey tnmeiato
Dabuggi
us to d locatig
Procass
Deb13
Debu 99ing tem is
a
populaly
proqran . Itb a Systemahe pocoss
P r o c e s
and ectfying e r r s n
datoch a pYoce
dlofach
or
iec e a
ww
Spotbn9 ar #ring
So that the software S behaing as expocfed.
expected.
w.Eqhtly
Seftwde when Various
tnpartiCulat
or
hade Complex systems & kern ov
Deugi yslen
Ona $y
n One
ouplad as chargas
Sub eysterms
asy
ause buds to emeqe
anothe.
tntesace
Types
may
Ervors
E ngi
Syntax EroTS
nee
Semantic Erro7S
rin
Runtime Errors
g.n
et
tnclude
Can
tn w wse
.Ea
lonq
fou
tegers
floatig point
integeis,
intagers
to a9 untagers.
n d Complax
aan
rtorra
syE
numbers are
whola
Callal Lonq tnlogers, long
nlegers
aa
uohole. numers
must
er
'
hare ngi
Dr' as the Suffi
ao a lla
lla floaking
floating
T h e Teal
hunberS oriactional
A floatog point
nee numbors
nwmber
Qie
is uplo
aceuvate upto
Point nurners A
rin
5 doumal places.
form g.n
Lwiten n the p
ohoa
et
,
nunbers aro
Complax
y ardpat tho imnginany
the noal paut
a=46 298 Floa
F Intog ype a) S b = 13 . 9 5
ENNA! DEPARTMENT OF
HDownload
eY From: www.EasyEngineering.net
SCIENCE AND HUMANITIES
Subject Code/Title:
Download From: www.EasyEngineering.net Unit:
Strings
Corsist
Stin
Stnn a sesuene ocharacters, Lohich may
w.E
>> ype lskr)
class 'slring'>
class 'stria
> type (sbr)
class gtring >
a
A Sring Consisting of syE ony apa malching quoles
are
l s t da . CJ to aCcass a n elarnent
We Can use tha. undex opocalor
üst having T eloments
Tnder Starts Jrom .
a
t a a ist.
wil have em to b.
tnder
ce)
Ce Print tl»t CI)
ww
Cn) Negativa Indocing
Cn
Python allows negative tvdezing
dor s Seduancas.
ow
2 to
to the last item in the list-2
The
.Ea
ndex -
l a t item
refe»s
and So on
tha
the
st
Second
'abe", , 2, 3, 'yz,
syE 4.96J
'e'
>tup = (10, ao, 'a', 'b', 'c') lor) tup =
0,20,'a, 'b,
To
To Creale a tupe
clude a Commard Jiral.
>>s ti 'a'
ty tt1)
Kclass 'tuple'>
w.E2,s,
>t C1, 4, 5)
asy
>Sprint()
E 'a', 2, 3, 4,5)
ngi
Dictionary
Dictionavy datatye
a a knd nee
of hash tabla.
. I} Contains
keyValua pis
ko
Dicbonaries
e assgnaad
are
ri
erclosed
access ad wsingng.
Cury braces
Sduare-
n
Can
and Values
3
brackab
be almost ary
et
Python typ
A dictionary key Can
'Age 2o,
Add':xxx' 1
Cea) dict Vame 'AnA
20, x*x )
dtct values (c 'ABn'
Prink
Prink ldict)
'Nane: PAApge';20, 'pdd':
'x*x *
Download
FENDAA From: www.EasyEngineering.net
DEPARTMENT OFF
SCIENCE AND HUMANITIES
LS
Subject
DownloadCode/Title:
From: www.EasyEngineering.net Unit:
Boo lean
Tho. Sumplost built n tye in ython the bol typ
it 7opve sents tha trulh Value» Tre or alse
>s x= ruo.
y = False
leg)
>> type(r) typey)
Kclass beot > class bool"y
w e Can
ww
Compa ra
assign
Nono to any
Variabe
Variake , ,
othes None
Ceg)
w
ye
.Ea
type (Nona)
objecs.
.ne
Yariablas Fxpressions and Statament
t
Variablas
A Vari ala. is a name tha Tefers to a Valua
Teserred
memory ocallons that etores
Vari ablos are
Tdenk
koyword
fes
anno
an
a syElengh
ba. oany
Expressions ard Batemenu ngi af Values. Vari ables
An epression b a
nee Conbiration
na lian any Vald
VaT ablos
Cormbi
ard opeiators. An ezpression
and
r ing n
Varablos
Python
opouator ardterals
rithmatie eyPresson
.ne
Sum
ab
= at5
a==b #Ralat
t
onal expresson .
an
thsBruc n thal tho Python
A
A slalamep!
eecde
interpro te Can
Prind Stetemant
Download From: www.EasyEngineering.net
NSTTUre oe DEPARTMENT OF...
SCIENCE AND HUMANITIES
LOG
Download From: www.EasyEngineering.net
Subject Code/Title: Unit:
AssignmcnB slalements
the Value to a riable.
Assigns
Phint SBalement
print la)
too
Tupla assanmant:
assignment to all of the eloment a tuple
An
An
usinww single
slatement
a assignment
LSi ng
By w.E
using this feature
using
allows
to be
a
tuple oflaviables
assigned aVaues
ues from
on the- let the
of an
asy
ight
assignment
the asignmen
a tuple.
En
n
gin
a,b: lo, do
Cog) Prtnd la )
Print lb)
eer
) Sunyo
Suay two Variables
-
a,b- b,a
udped
30,10 t
Print la,b)
es
number Variables tha left and the nunmber|
on
Tha of
Values on the ght
g hl
hare to e ama
Com ments
starts the
with thehash character
A Comment python
to the end of the phy si cal ine
and extends
b
Very easy
oComments ython
Ha king u se.
Hakang lina. t o put Code
Cormment
Qan un clude. a
Ou C odcee ard
Can
be used to explain Python
Commcnts
Tectablo
ma ke. the. Code more
hen tosting
to prevent execu ion
Comments an a uba
Code
ww Tiple
uotalion . . . "*)
*) for
for
w.E
u
It ë alSo poesle to
multiune lommeni
eer
They aue
une Cormmens
Singla
-
Sngle une.
Multi
ommenb :
üne ommen
in g.n
(1) Symbot and
A Singla wne
menti oning
nment
thal
bequns
the
wtth
whola lue
a hash
lune
une
should b a
Should et
we-ful wndithe end o the
Consi docod
omment ntund
n.
to a Vaiakla
asigns
n 50 # 5 0 value.
#
i n a . ammenls we
ua d to bmment
n eecd ommenl
Vhen
Mull ine lanmen u s e ful
double duote ("
quote
lines. In ythen tripla
on many used fo Hullne ommen!tng.
and single quole ( ) are.
Author ; Ann
Dept CS
Se cdion A
Literals
Litoras a raw data ,9iren
a
Varia bla. (o) Consanl .
Variaus tyes o terals
terals
thee are
Tn Python
Numevt lerals
Slri nq ilorals
Speial lorals
*Boolean lerals
Numerii terals
immutale .Mume7L teras Can
Numeric tnas are
be lorg wtow
belorg dferent Numeri cal TRS
Intege w.E loati leval Compler tesal
tera
*
octal
>
iterals
Print la)
lbase ) gin
To tndicata. an
eer ProjJix
octalle ral we
wllue the
8)
ing
Casa
Oo lTDe (tow fotloud uppe lo) Lower
.ne
Oculpud 6
Heradedimal
> Print (z)
ileral Cbase 16) t wll the
dicaBe hoxà decimal teral we use
To
lov) Or.
A
Ox Lybx1b= b
Pref
Eq) >> 7-Ox A to xlb : lbo (4)
>print( 166
b
Sloal teal f-hs.a print (1) oudpu 4s.b3
Complar bile.al >>a - 413.5) >print (a) oud pud4t9.5
Booloan Lloca): >S a ru print (a) adpd Tua
TTuo
Stnng tea s S: "siring
"
>>> audp String Jitexal
Prin1 (s)
Spocial litoual s a : nona }a==none DudpdSpeuiial
teral
pTnt special Download
uteLaj
ENNA
From: www.EasyEngineering.net
DEPARTMENT OF
SCIENCE AND HUMANITIES
NOOY
Download
Subject From: www.EasyEngineering.net
Code/Title: Unit:
yacadanca fopeas
thal uod lo mani puloo
Oferalors av the Construcb
avo
ncude. 4, - . +
the Valuc.
o opeands , o e hasid oporand,
and
ww
AsSanmen oevaBors Hembershp oforaBors
w
Loy, ce opexa tos
.E
opeTator Precodana
4Tdenty ope ratovs
asyand
s
Assoialiity
When an expreson has more. than ne opera tors then
it the. Te lafie En
Priori ties of the operalors with res pmcl to
each thaB dolamined
ofher gin
tha order n toheh the expre
expro Ssion
Ssion
evakuatal.
e
Description. er
operato7
vponen lialin
i ng.
Comple ment,
Multi ply, dii de, modulo,
net minus
unary plus unary
_ard flooT
divison .
ILDSTRATIVE PRoRANS
two Variables
the Valuos
Exchange Exchang
in third Yaiable.
in
a- nt (input Ente the first number "")
the. Second number"))
b nt (inpul Enle
Print Before Suap") Outpet
pint "a -", a,")b=", b) Enle thanst nunbe
temp a Ente tha Se cond numbes 3
bternp ww Be ore
a &
Swap
b=3
Print nf ter Gwap")
Pi "a
w.E
", a
"b=",b
Afle
a 3
Swap
b:9
a
: ,
syE
third Vaia ble
withoul usi9
("Fnte tho frrst ngi
nunbe "))
a=
b: t
t (inpl
(hpu Enle
the Secwrnd n
number "))
eer
Print Before tuaP ") ing
Print"a= ",
"b= ",b)
.ne
b: a-b
Qdpd t
a = a-b
Foto the fvs numke
Entos the Socund nurner: 3
Print nfter Suwap')
"b= ", b) Bejore Swap
Print a - ", a,
b - 3
a =
Pfte Suwap
Q 3 2
J
Print (i,' Rolalion,&)
ww
[,2, 9, 4.]
w.E
ar (1,3)
distance. (,, J2 )
y,,, gin
dist =malh. ee)+r*2)
Sl (t2 -K)** +1a-4, 2
ing
d
elurn dist
dslane (,4,15, 16)
.n et
Print pistance.
between tuw points',d)
Oulp
beluwcen tuo poin
Pstance
b.9To5l214 847714
o
DEPARTMENT QMANITIES
Download From: www.EasyEngineering.net
AND HUMANITIES
SCIENCE
Subject Code/Title:
Download From: www.EasyEngineering.net Unit
Cerum
w.E8.84
Mthon Paqan to
to Conlgpada.
convet
t
faranhat Progran
two variablos
a
to axchanga the value
a,b b, a
Oudp Prin" Afte svap")
Enla the faicnheit yale. n3
Print a =", a, "b- ", b)
Con 19ado : 4s.o Ouru
Entea 1o Fme b 2o
Bejore Suuap a =
Lo, b: 2o
a 20, b=o
Afte swas
Download From: www.EasyEngineering.net
S
DEPARTMENT OF
SCIENCE AND HUMANITIES
DownloadCode/Title:
Subject From: www.EasyEngineering.net Unit:
ourut w.E
Entea the s i d e q tke. triande
he lrlangleasy
1s
1
Fnle the
3d side
the 3ds'de
t
the trtaala
w
En
Fnles
gin
hrea 56.5b85424949.
eer
in g.n
e t
Download
cHENNAI
From: www.EasyEngineering.net
DEPARTMENT OF
SCENCE AND HUMANITIES
Subject Code/Title:
Download From: www.EasyEngineering.net Unit:
Tuo Marks
Dofne Python ?
Python s an objech oriented hgh leval language
and mu ti purpase Programminq languag
'tnderpreted ,a na mic
Tntepreted longuage
w.E language
Froo
+objedoente
ard open SOurce
*Extens ble as
yE
Whod Python
n inteprete gin
The engne tha translakes ard eruns
eri Pythonis Callad
tho Python tnteurete Thoo two
ng. the
w0ys to use i t
tmmediale
ummediake mode
moce.
Python Pronpt
ard Sipt made. .
The thtepretes es
The >
the
prompt
net alled
to thdcate
atte 01
a humber that a pmgram manipulaBes.
a
Python ?
Lis He standaud daa typas Python?
TYre NumberS strings ist ple
Dhetiona
Download From: www.EasyEngineering.net
CHENNAI
NSTUT
RSY
DEPARTMENT OF
ScIENCE AND HUMANITIES
Subject
DownloadCode/Title:
From: www.EasyEngineering.net Unit:
mode ad made
6.PoLanta betwean nteLactive eipt
Tnteractie modo Scipt made
A uny 1 w g he Pythonn
P way ing
the Pythan
ntepre te tread and exeuke
nte pretes statermenb
ytypig Statemenb n a ipt
at prompt
edit the ade
edt tha ada
3. Can Sare G
2 Cannot o ve and resu l t
no See the
se can
3. e can Sae tho resulb m medêatey.
nnediaely
ww be by an dlantifer
7 stout
w.E
tha rules
Can e a
tollawed
Comnalon letters, diq.t
Cundetscor2
Tden"fier
keycwords asy
Coords Cannot e mel as denbtfers
An
An don bfies canno
Start
En th a digit.
Lka!,@,#...
E k a ,@,# h au
hve cannol we
ary special
Symboto
gin
denifer
Can
lo 6 any longth. eer
Idenilerss
t python ? ing
8Dno
reserr
words
eser ed Coovds t
Cvevds .ne Python
Pthen Ne annot
t
ae
the othev
twords any
Key Vaiatla
Vauala
n
naam
maa unction
name or
as
a
koywora the Syntax shuchue
wbe ued b dofine
identier Thay
thethe pythonlangu
not
F a s e , True , f , wkilo
Ce)
Deneunchon
s b pmram
Whuch Conss
sts of sels sf
a
Functi on
tosk
tnglructh ons
webpeform a peufe lage proqram
,
A
10
Defina Expressions ard Stakemenb ?
Expressfons
is a ombinallon f values ,
variablas
An kxpressi on
State ment he p
tho
SBatermenb an
ngi ae
flas o xecuho
tima un chon deiniliond do
,
not altes
nee the
the PLoanm
rin
Peine paLamateS ad avgumens g.nparthests
et
en
Ceg
cog da Sum la, b) :
Sur )
ine modules Python
A madula u a Jla Containinq
then aRHon
uncion taBomants ard thstructona
augumens
kozpord
peault angurnan
Redurergumens
tknt
s yE time
ngi
nee
rin
g.n
et
ww
w.E
a syE
ngi
nee
r ing
.ne
t
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
asy
E ngi
n eer
i ng.
net
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
asy
En
gin
eer
in g.n
et
ww
w.E
asy
E ngi
nee
rin
g.n
et
ww
w .Ea
syE
ngi
neer
ing
. net
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
asy
En
gin
e eri
ng.
net
ww
w.E
asy
E ngi
neer
ing
. net
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
asy
E ngi
nee
rin
g.n
et
ww
w.E
asy
E ngi
n eer
i ng.
net
ww
w.E
asy
En
gin
ee rin
g .ne
t
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
asy
E ngi
nee
r ing
.ne
t
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w .Ea
syE
ngi
n eer
i ng.
net
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
asy
E ngi
neer
ing
. net
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
a syE
ngi
n eer
ing
.ne
t
ww
w.E
asy
E ngi
nee
rin
g.n
et
Statement ,
Retai) B:) Prepaation.
ww
Secuendo
data structura a roup of data elamanb that
ave
Put togethar
w.E
undeY one
Data StucBure dejines
ovganixing dala
name
spacifie index.
Secuona
Saduen o
ts
data Structuro
undex Valuos
each
Starb from
element
E
Zero ard is
en the
has
the Sec
a
ueen
ecu ngi
automatically
nce
The
The
ncremented for
elemen n
the nex
nee
List Values, Tha rin
Valuos i a üst a v e
ist is a Sequenca.
Valuos, ard it
of
also callod a s elemenb
alled as elhments
g.n .
Comma.
List
elementu
separatod
must
must
b.
enclosed by cLar
bracke [.. ] and
brackeb [
et
Valuos
the
Syntax List Variable val1,vals...
elements
element
list that it can have
key feature of
The
koy
The
a
called
aalled an
an empty
emply
A s t thaB Contai ns no elernan á
st
Download From: www.EasyEngineering.net
CHENNAI DEPARTMENT OF
ScIENCE AND HUMANITIES
ECHNOLOey
Download
Subject From: www.EasyEngineering.net
Code/Title: Unit:
Pint
pint(
w .Ea
Frst elarnent
st
lst[J)
[1:3J", Jot[1:3])
st [:3 [ , 5]
[s,5,25]
pntst[::2}", sy kt[::2]
En
t[:2:
Updating Valuas in st
sts aro mutabla .
gin of
The valuo of any element
sido
nsido
elamen
tha Lst c a n be changed
ble
at
eer
any time. The
point
with their ndax Va lua
,the ndex
in
access
Of the
of
Lst
the Ust are
ends Lwith n-
a luways starb th
30, ho g.n
>
> t
st
=
[3) =15
e t
>ssAst
w.E lsk
>> atb
=[1o, 'a']|
Ist =[to, a'3
a','']
Repelition
Tt
a shy'*yE
Ropeab
perforad
elomans tha 'st.
opeiator.
,'a', 1o,a)
chacks f he value b
ngi ' a [io,2o30] False
Present the st
nee
nol n
chocks 1f tha valuo n o t
Prosent in the ltst. rin
' o not
Truo
g.n
et
Retuns maximum valuo ss lst = [2, b8,45J
max max (lst) 13
t h a list
w.E
Prpords an elomant to tha kst l a s | lst [ i , 5,2]
an eament at tha erd of the. ,5,2,8
appondt) |add
a
ISyntax: tst.appand s(obj)
Jtst
yE
Istppard (8)
lst
ngi
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. nee
Synlax kst. indez lot)
rin
insertC)inde
Tnsart objoc aB tho 6poctfiod s
n the list.
lst =l'a', 5, ] |
g
bs lst insert (1, )|'a', '>, 5,8] .ne
Suntar: st.insentl'indar, obj) Ast
pop ( [indax])
Download From: www.EasyEngineering.net
SHENT DEPARTMENT OF
AND HUMANITIES
SCIENCE
LCHNOLEa
Subject
DownloadCode/Title:
From: www.EasyEngineering.net Unit:
w.E
Laoping n usts
Python's for
a syE ard tn @nslruc ave useful toorking twhen
ses.
w th
acces each
The for Va
eloment n a st.
n in s Statement a n easy
gin
easy way to
HENNAM DEPARTMENT OF
Download From: www.EasyEngineering.net
SCIENCE AND HUMANITIESs
Le
Subject Code/Title:
Download From: www.EasyEngineering.net Unit:
Muta bit
The tst a dala shrcture This means the
muta bla .
ww
List aliasing_"
An bjec wth more than One Teerance hab more ond
than one
name, So w.E
tua
Say that the olject b allasel
asy,
b=a
bua En
True gin
a7eferS an ohject ard assigh bza,e then
eri
both Vaaial
Vaial
9He b the
Garne
a
objoct. The assocakén of a Variable 'th a n
ng.
Dbjed b callel
Cloning Lst :
roference
n et
Assgnment sBalemanb python do no Copy objecb
coP
ketveen tuo objecb qo muta ble
They Sumply bnangs Croale
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
ww
L,3,)
nlst ,a,3]
Oul pud
t[oo, 2, 30
nlst L2, 3)w.E
Lst [i 1o, 3 nbt [o, 20, 30)
asy
List auametevs E ngi
hen wo pass a ist to a Juncticn, 1kaunctóne
to the Rist.T he n e e
funclicn modfes a ist
change ri
a eeenco
Paua me ter, tha aalla See tha
ng.
the bsl
de hsval lt);
tingert 1,26)
ne t
Ast[ab, 3s, 49, 57
Print Belore thsevlon ", lbt)
insval (ttS
Print( nfle hserun " bst)
72349
3-57
Download From: www.EasyEngineering.net
COLOg
DEPARTMENT OF
SCIENCE AND HUMANITIES
Subject Code/Title:
Download From: www.EasyEngineering.net 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)
wwthC1,2,3)
Tuple ww dtfouan dabatPeS
hello", .5.14,EaTre , 98) 75,
rin Soma
elomant ,hvaned t ad
tuple with
g.n
one
Cwhen e Creakng a
Lo tl et
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)
Download From: www.EasyEngineering.net
ENGAY
NOL DEPARTMENT OF
SCIENCE AND HUMANITIES
Subject
DownloadCode/Title:
From: www.EasyEngineering.net Unit:
Returns asy
minimum Yaue un | a: 5,4,0, 12
mn
tuple E ngi
mn la)
Returns maci
tuple
mum Valo i
n eer max
a 5,9, to,
la)
ing
mar
tuple
Retum to)Convert tuplo . tupla
.n
([[o,ao,a0) Cto,
upla( he.lo') h,'e'',"',
et o')
20,30)
Swap w
tupla as9ignrnen
two
>S
Print
a,b : b,a
( 'a:
asy
', a, b : ' , 6)
a;bsb En
Tuples as etum vaues gin
Vavi abla lenth arqument tuples
Varaba numer oCqurnent
the
Tuples can albo e etuvnad by
Taturn Valuoas
Can abo ba eer pasead to a anci on
funcion
ing an +
as
Dic tlonaios
Dre tionay s an unordaad collouluin elomenls . An e lorment
in dicfionary ho a koy value pau, Al elemant cn dicionary e
ww
+Add elomant
w.E
Mambershup
0paradions Doscripu
Exampla
Croating asy
a Creabng a dicionauy
th
of difauant daBakypres
S>> a : 5'Namc': 'AAA',
'no': 123
dictionary
En elarneri 2Nama': 'AAA', 'No':1233
elemant
Accosi ng
usinq kep.
tha
eer
123
> ing
af no=b18
to koy
.ne
value
Assigning a new
L'AgeJ:18
>a
odd elerrant dicionay wth key
ama' 'AAR, 'o : 16,'oge ';18 j|
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
wwdiel-keys (ti, 3)
keya) a . keys t) t
a
displays liet of kas
dicHonay
Yaluas() w.E['ona a.valuos c) displays ist
| dictidnay.
y values
Pop(kay)
aict
a
valo» [
a.popl1) sy
two)
Remove tho elenent with
two' E
SSS print la)
ngi
'3: kwo Koy and neturn Hs Valuo
om tha dictionay,
Sat dodaul a
kay, value)»y a.
neer
='sub: 'Python','Nauks':95
got dataut lpopt ', 'Hech')
key
e
o the dictionau
turns ts Yala, kay
Print la)
': Na) hvth a value f ditii ing
not Present, nsert ke
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.
st Comprehensi on
wexprossion
Syntar
st= ww fo elomant s t f t conditional
this .Ea
eduivalond
b tb
or eloment sstyE
ngi
Cond
Containingne
exp
7ollouwod
ConSis ibrackols
e
horve for ri
an
expresSion ,
clauses
a tor clause then LeLo 0r
r eterns
returns a ng.
vesult ist.
vesult i st.
into one n
Comprehension aways
The s t
The
Proam
to Combine thrrae lines
i
Code
Codo tnto Dre
lb)]
et
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
Download From: www.EasyEngineering.net
Download From: www.EasyEngineering.net
Histo qrams
dyrantion
anothei ddmantion
the Verbica avis
w.E
hongon
and the
Halplst lib Can e lwa b
create histoqamS usually
t a
also sy
has bins where eyey n has a m i n i m u m ard maximu
oquoncy tetwoen and vnfinile |
Vaue E
Each n has a
ngi
eeg) Uport
tnpoyt
num
matplo b
np
mlab an
ne
mlob
as plt eri
tinport ratplst Lb pypot
wo n
X=1, 22, 23, 3s, b,1,8, 45,b5, 18,
g.n
hun bins =5
faths = pll.hist [7,num_ bins,
jaca slor lue', e
alpha = o.5)
t
n, ba,
plE Show C)
20
1 , 33, 5 3
Excha oge
ngranqe
ho
Print (Enlä
Fnle he elomen lo,n):
The
Sortad
i1
n ee
7
apprd
Valuos
8
ae
lst. Gt lapud ()
pass
53, 3 , 1 9 , 1
Sortods}
8 , 14, 24, 27, 3
j- 53 33 CT) > Chare
8, 3 , 3 , 19, 1
J=
ww
4 3,8 int"prndut
4
36 w
1 4 lT) &change
8 > Condikon
21
.Ea
ailb pen" 28 "penci) ":
Fase:54
5
H 24 27
syE Print lprod )
i u h , n)
378 T
441
xchange
33b ngi Print ("Curvent
Stock de tai u)
|J:3.
34
218 (T) Exchange
21 3
Dutpu
nee
Pnnt(pod)
T) Excharge
Procuch Pra detai
rin A8
J
24>s
6 24. 27
36
biscuil: 2s, g.n
hocotake : to, pon
4>8
a4
(T) Ex
change
21
-
sb Produ ct
Ponti);8, Enaser
lock debaib.
chocolale
e 8o, fon :
t 268,
2bisuil : o,
[Ratail b l prcpaualan ponct)58,Era ses:5
Product detais
product deia
V
SBock
qvrent
Prod L 7o; chocstale , ponab
total = total t pite 2
bisu 8 3
ponu); 56 Frus ;
prod [1J prod [«]-n
SBdent
AHendanta ": [eq.0,97.003
HS Sgnment =aveLage l
rame": "pacpak", *Pesess
man
L"nss gimend ") n3
ww Altendoance )
nsS mer
5o. b
Loo.0, 81.o, 75.o,
AHlendante z
ayemge lStudont
Llo.o,15., 18,0]
w.E
to =o.b ASsos Srent tO3 *
ttondan to' :]wo.D,
na]
too.DJ4
asy
¥ n2,
Studons [n,
=
HssgrmenBtoa
*AHerdbruHor Sudant s h u d a r s :
return tot
E
(score) ngi Print
Shudont [name
fu B6oesSmend )
studant
)
, e) -g.
mauks
Pin "Aeage
eh
refurn n
Score=");
eturn A*
Print(kuma"
n)))et
Gel-avaage lni)
letlet-7ade
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 -
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,
ww
Lo. oj Lo,oj
A VeLage matks
KunaY: A
Veena w
O
BT .Ea
Deepak
class AveLage syE
Masks70.o
ngi
nee
rin
g. net
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
Ongnalww we
reed t ma ka.atallaN
leto maka
be2 atlo
o
process
copy
atst
tst clohirg.
clohing.
w.E
This
. tho refeena
ust
1,2,3,4)
asy
az
s
Ceg)
b a[:3]|
En [,
3. Define gin
st aiasin9 bla b
Cwith example .
anothe
anothes ,
Loth
oth Variale efers
Variabe ejers
w a asegh ee
the s a n e obyett.
One Vaia
rin
to
2,aJ
>S a: J,2, 3] b g .ne
True
a is
two dfeand
dffecond names
names and b,
a and
a b,
t
ita
i u
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
Download From: www.EasyEngineering.net
Download From: www.EasyEngineering.net
dol t : 1
stfinder
d e l b+ LaJ
w .Ea
C,3,41
tupla ?
String a
7 convert
syE
a
Hocw coverted a a tupla by uing tha tuploc
e
A Strng an
hunclon ngi
'm', n
togss uple ['proqammig9)
P ' o ' , 'a','¥ 'a', eer
'm', 'i', 'n','7)
Python program
to Swap two
Valuos
i ngtupla
8 write a
a,b =
Print la,b)
b, a t
usa t tplas ?
oint out the methads
yeturns tha numnkeu clemens hhich i afua
Count t) Tt to
the i e n 'elonment
C o e r ca o n
Data typo albo knowrn
to anotho cal type . s
Vaiable
t(950. 15)
tog)
ww
s z l o a (200)
wrtaa
pythcn w.Eprogram
geneialo
to genoLala
a
ddichionauy
chonauy
Prnt Cd)
ad eevse looku e eri rressonding
C o vrosponding
Valuo
Valuea
5 Peina lookup
okue
tho procos9
dicionauy
indn the
indin9 the
.teg)
ngkay.nt
hay
Valua = did
orn
et
a
Hor
Tor tha
the a ven
kay the the
Procos9 nng he
laokup
koveyse
Yen value
b remembaring
oremembering result results
Deine memorO"
e#echvely ejors ord tho returning
vetarnirg
ord he
tha nathocd pubs
Memorinauon
ww
w .Ea
syE
ngi
n eer
i ng.
net
ww
w.E
asy
E ngi
n eer
i ng.
net
ww
w .Ea
syE
ngi
nee
rin
g.n
et
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w .Ea
syE
ngi
n eer
i ng.
net
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
a syE
ngi
neer
ing
. net
ww
w.E
asy
E ngi
nee
rin
g.n
e t
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
asy
En
gin
eer
in g.n
et
ww
w.E
a syE
ngi
nee
rin
g.n
e t
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
asy
En
gin
ee rin
g.n
et
ww
w.E
asy
En
gin
e eri
ng.
ne t
ww
w.E
asy
En
gin
eer
ing
.ne
t
ww
w.E
a syE
ngi
nee
rin
g .ne
t
ww
w.E
asy
En
gi nee
rin
g .ne
t
ww
w.E
asy
En
ginee
rin
g.n
et
ww
w.E
asy
E ngi
nee
rin
g.n
et
ww
w.E
asy
En
gi nee
r ing
.ne
t
ww
w .Ea
syE
ngi
ne eri
ng.
net
ww
w.E
asy
E ngi
n eer
i ng.
n et
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w .Ea
syE
ngi
n eer
i ng.
net
ww
w .Ea
syE
ngin
eer
ing
. net
ww
w.E
a syE
ngi
nee
rin
g.n
et
ww
w.E
asy
En
gin
eer
ing
.ne
t
objett
o o2-10 t634 4o 218229
Uo sit not On modulaa Pesian Cau Sanl8, 21
w
peommw
Moduls ase PsawaRtten
Commor tasts lite
pucos coda tholt al uLo
genesabng landdonn numbers
PEomingw .Ea
mothanabiCal opeaatons
oith-P exunsion tho has
A Module à a
syE
i
tunctions ard Vauables
that
t a t uould
uouulA
ngi
al
nions
ug n otha p a a m .
Moclutes a Uad to
nee
baaahdouon asapaiam
CD- o
what Pomat operator?
a n opeiator C/.) holt talcns a
*Fomat operabor
arda upl au înput ond pnssats a lbung
Hormat slu formauttad a
umont o he ple,
ha Enluds ta
petfind by ha tonat sting
. i tha maluus perator
when appiid to inteaAs
& the
But ohan the fiut operand à a Stuhg 7.
fomas opehato.
Download From: www.EasyEngineering.net
Download From: www.EasyEngineering.net
A well
w
.Ea dauctoias fo enatey
angantiucd kResanch of
Pthen
s yE for dtsackonles
packnga haa ad nodutes
ngi
what aa Excaptions? nee
rinand tha
kssoxs Can alao ocaus at uuntirns.
aaa Callud Exutptions g.n
eA b
e
to
t open doea not
e i t ALNo
ww
w.E
asy
E ngi
nee
rin
g.n
et