GE3151 PYTHON UNIT 2 NOTES EduEngg
GE3151 PYTHON UNIT 2 NOTES EduEngg
CONNECT WITH US
WEBSITE: www.eduengineering.net
TELEGRAM: @eduengineering
-
INSTAGRAM: @eduengineering
MENTS
UNIT T DATA THPESFPRESS)ONvs, STnTE
Vauiou Problem
nginaering problama
Applcaloms python
u
solving
Tntroducton t Python
Rossum duing 1985-
Van
Pythen was c veleped by bjuido a tie,
thles aBlie,
lod, ile
tn tee pn lad,
a geneca! purpase. tntepe
1990Pthan level
languaqo.
Proqramming larguago
object oñented and hih
Rython is intexpraed
at run tima by the tes preter. So
Rrthon is processed t.
need to Compile. a Progam before execuling
there is ho
Easy to loarn
is ceary dofned
and easily readable
A Python Proqram
s Vey sumpla.
|The trcture. of. tho Prog a m
Vorsatla.
Imago procass'ing
ScieNtfic and cornputalional applicaluons
*Ujamas
Ente prise and business applicalions.
Opovating Systom S.
anguuaga deelp mant
Netuwort Programming ard Prvto typing.
TELEGRAM: @eduengineering
FSNUA DEPARTMENT OF NEOey SCIENCE AND HUMANITIES
Subject Code/Title: 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
Socuco, Thteaprate odput
Lcode
Compilo
Pre Pre
Pocassing CompiloProassnMachino soutput
Souco
Code Codo
and Inteuprate
DHouona batwaen Comples
TNTER PRETER
CoM PILER
one
Scans tha entire
Program Translatas program
Compila bime.
transla Bes it as a low laval stabement at a
and
language coda ü
No Tnkesmediake objeck
Tnkamediata ojeck code a Geneatad Generaled.
statemanis aua
Condibonal control stataments ad
Cond:honal Control
executes Slowe.
Ereutes faske.
Inteuactva moda
When wo type tha Python proqram in unteacBye mode it
dioplays the rasul mediatoly.
The charron > the prompt the tntopratos uses to
ndlcale that it Teady to ente coda.
Ceg) 9 t
loo
» print (e Tntoac tive moda n python ")
Tnteractire moce th Python
ADVANTAYES
Python Tnteiackme: mada. i gpod enoueh to lcan
exporiment or Explora
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
TELEGRAM: @eduengineering
STTUso DEPARTMENT OF
SCIENCE AND HUMANITIES
Subject Code/Title: Unit:
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
b 9
C = atFb
Pint(sun;"c)
Otp
Sum 16
betwcon Intesacti ad Sipt moda
Difeono
Thteaacin moda &ipt mode
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
a piece
tha nunbe sf bug
s
Types Ervors
Syntax EroTS
Semantic Erro7S
Runtime Errors
TELEGRAM: @eduengineering
CHENNA DEPARTMENT OF
ECOy SCIENCE AND HUMANITIES
Subject Code/Title: Unit:
Complax
ard y tho imnginany pat
the noal paut
a=46 298 Floa
F Intog ype a) S b = 13 . 9 5
TELEGRAM: @eduengineering
H DEPARTMENT
eY SCIENCE OFENNA!
AND HUMANITIES
Subject Code/Title: Unit:
Strings
Corsist
Stin
Stnn a sesuene ocharacters, Lohich may
ist
Tang D ornpound dalatypes often raferre
Python ofers a
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)
'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'>
TELEGRAM: @eduengineering
ENNNO DEPARTMENT OF SLO sCIENCE AND HUMANITIES
Subject Code/Title: Unit:
>Sprint()
'a', 2, 3, 4,5)
Dictionary I} Contains
knd of hash tabla.
.
a a
Dictionavy datatye erclosed Cury braces
Dicbonaries are
keyValua pis
ko Values Can
e assgnaad
access ad wsing Sduare-
and
3
brackab
be almost ary 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 *
TELEGRAM: @eduengineering F E N D A A DEPARTMENT OFF
SCIENCE AND HUMANITIES
LS
Subject Code/Title: 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
Nono to any
w e Can assign
Nona
> a =
Variablas
A Vari ala. is a name tha Tefers to a Valua
Teserred
memory ocallons that etores
Vari ablos are
an
thsBruc n thal tho Python
A
A slalamep!
eecde
interpro te Can
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
slatement
single assignment
usin
LSi ng a
allows a
tuple oflaviables
By using this feature
using
assignment to be assigned aVaues
ues from
on the- let the
of an
the asignmen
a tuple. n ight
a,b: lo, do
Cog) Prtnd la )
Print lb)
two Variables
-
Tuple assignment
) Sunyo
Suay
a =lo
b 30 udped
30,10
a,b- b,a
Print la,b)
es
number Variables tha left and the nunmber|
on
Tha of
Values on the ght
g hl
hare to e ama
TELEGRAM: @eduengineering
DEPARTMENTOF GHENNAI
SCIENCE AND HUMANITIES
LCNOLOey
Subject Code/Title: Unit:
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 Code
Coce 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
uotalion . . . "*)
*) for
for
u Tiple
It ë alSo poesle to
multiune lommeni
They aue
une Cormmens
Singla
-
*
Multi üne ommen
ommenb :
Sngle une. wtth a hash (1) Symbot and
wne nment bequns
A Singla should ba
Should
thal the whola lue
menti oning
lune
une
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 necd to bmment
need ommenl
Vhen
Mull ine lanmen u s e ful
double quote ("
duote
lines. In ythen tripla
on many used fo Hullne ommen!tng.
and single quole ( ) are.
Author ; Ann
Dept CS
Se cdion A
TELEGRAM: @eduengineering
SNU DEPARTMENT OF
ScIENCE AND HUMANITIES
neNGLOgY
Subject Code/Title: Unit:
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
belorg to dferent Numeri cal TRS
loati leval * Compler tesal
Intege tera
numbors
kegular unteq Nomal tnlege
Cea) >ya = 525
>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 >>> Prin1 (s) audp String Jitexal
"
yacadanca fopeas
thal uod lo mani puloo
Oferalors av the Construcb
avo
ncude. 4, - . +
the Valuc.
o opeands , o e hasid oporand,
and
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
Be ore Swap
bternp a & b=3
Print nf ter Gwap") Afle Swap
"b=",b a 3 b:9
Pi "a :
", a ,
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
TELEGRAM: @eduengineering
HA DEPARTMENT OF SCIENCE AND HUMANITIES
Subject Code/Title: Unit:
J
Print (i,' Rolalion,&)
[,2, 9, 4.]
ar (1,3)
elurn dist
Oulp
beluwcen tuo poin
Pstance
b.9To5l214 847714
TELEGRAM: @eduengineering
o
DEPARTMENT QMANITIES SCIENCE AND HUMANITIES
Subject Code/Title: Unit
Cerum 8.84
ar Sun3
Oct pu Prnt('sun: ' Sun,'Av9:, avj
Otput
Conigrade. :45
En tee the Fnle a IoD Ente b aco Entec 300
Arg 300.
The Jacnhe?l - 13.0 Sum boo
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
TELEGRAM: @eduengineering
DEPARTMENT OF S SCIENCE AND HUMANITIES
Subject Code/Title: Unit:
TELEGRAM: @eduengineering
cHENNAI DEPARTMENT OF
SCENCE AND HUMANITIES
Subject Code/Title: 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
Cross -plalfomm larguage
Froo ard open SOurce
+objedoente language
*Extens ble
atte 01
a humber that a pmgram manipulaBes.
a
Python ?
Lis He standaud daa typas Python?
TYre NumberS strings ist ple
Dhetiona
TELEGRAM: @eduengineering CHENNAI
NSTUT
RSY
DEPARTMENT OF
ScIENCE AND HUMANITIES
Subject Code/Title: 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
by an dlantifer
7 stout tha rules be tollawed Cundetscor2
Comnalon letters, diq.t
Tden"fier Can e a
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
ae
at
ecubed one a
SBatermenb
State ment he p
tho an
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
thraading
Collechors
strin
time
tknt
TELEGRAM: @eduengineering
DEPARTMENT OF
ENNAIC
TCHINOLOg SCIENCE AND HUMANITIES
CONNECT WITH US
CONNECT WITH US
WEBSITE: www.eduengineering.net
TELEGRAM: @eduengineering
-
INSTAGRAM: @eduengineering