Python Unit 1
Python Unit 1
NTRODUCT
IONT
OPY
THON
UNI
T-I
PY
THONI
NTE
RACT
IVEANDNON-
INT
ERACT
IVE
(SCRI
PT)MODE
I
nter ac
tiv emodei sba sedont hiside ologyonl y.I
nt hei ntera ct
ivemode
aswee nt erac omma nda ndpr esse nte r
,thev eryne x tstepweg etthe
output. Theout putoft hecodei nt hei nter
ac ti
vemodei sinfluence dby
thelastc omma ndweg iv
e. I
nteract i
vemodei sver
yc onveni entfor
writi
ngv eryshor tli
nesofc ode .I
npy thonisi tals
ok nowna sRE PL
whichs ta ndsforRea dE v
aluatePr intLoop. Her e,t
her eadf unc t
ion
readsthei nputf r
omt heus erands t
ore si
tinme mor y .Evalfunc ti
on
evaluatest hei nputtog etthede siredout put .Pri
ntf unc t
ionout puts
thee valua tedre s
ult.
T heloopf unc ti
one x
e cutesthel oopdur ingthe
executionoft hee nti
repr ograma ndt ermina teswhe nourpr ogram
ends .
Thi smodei sv erysuitabl
ef orbe g i
nnersi nprog rammi nga sit
helpsthe mev a l
uatethe i
rcodel i
nebyl i
nea ndunde rstandt he
executionofc odewe l
l.
E
xample1:Torunpythonincommandpromptty
pe“py
thon”.The
n
s
implyt
ypethePythonsta
tementon>>>prompt
.Aswetypeandpres
s
e
nterwecanseetheoutputi
nt hev
erynex
tli
ne.
#Py
thonpr
ogr
amt
odi
spl
ay"
Hel
l
oGF
G"
pr
int
("He
ll
oGF
G")
I
nt hes cri
ptmode ,apythonpr ogramc anbewr i
tteninaf i
le.Thi
sfi
le
cant henbes avedande xecutedus i
ngt hecomma ndpr ompt.Wec an
vi
ewt hec odea tanyti
mebyope ningt hefi
leande di
tingbe c
ome s
quitee asyaswec anope nandv i
e wt heentirecodea sma nytimesas
wewa nt.S c
riptmodei sverysuit
a bleforwr i
ti
nglongpi ecesofcode.I
t
i
smuc hpr eferredoverinte
r a
ctiv
emodebyex per
tsint heprogram.The
fi
l
ema deint hescri
ptma deisbyde f
a ults
avedint hePy t
hon
i
nstallati
onf olderandthee xtensi
ont os aveapy t
honf il
eis“.py”
.
Ex
ample1:I
nor
dertoexe
cut
e“Hel
l
ogf
g”us
ings
cri
ptmodewef
ir
st
makeafi
l
eandsav
eit.
Nowweus
ethec
omma
ndpr
omptt
oex
ecut
ethi
sfi
l
e.
Appl
i
cat
ionsofPy
thon:
1.
WebDe
vel
opme
nt
Pythoncanbeus edtomakeweb- a
ppli
cati
onsa tarapidrate
. Whyis
that?I
tisbecaus
eoft hef
rameworksPy t
honus est
oc reatethes
e
appli
cat
ions.
The r
eiscommon-backendlogicthatg
oe sint
oma k
ing
thesefr
amewor ksandanumbe rofl
ibr
a r
iesthatca
nhe l
pintegr
ate
protoc
olssuc
ha sHT T
PS,FTP,
SSLe t
c.ande venhel
pint heprocess
ing
ofJSON,XML ,
E -
Ma i
landsomuc hmore.
Someoft hemostwell-
knownframeworksareDjango,Fl
ask
,Pyramid.
Whyus eaframe
wor k?T hesec
uri
ty,
scal
abil
i
ty,conveni
encethatthey
prov
ideiscomme ndabl
ei fwecompar
eittostar
tingthedevel
opment
ofawebs i
tef
roms cr
a t
ch.
2.
GameDe
vel
opme
nt
Pythonisa l
sousedinthedevelopmentofi nter
a c
ti
v egames .
Ther
ea r
e
l
ibrari
essuc hasPySoywhichi
sa3Dg amee ngi
nes upporti
ngPyt
hon3,
PyGamewhi chprovi
desfunct
ionali
tyandal ibr
aryforg ame
developme nt.GamessuchasCivil
i
zati
on-IV,Disney’sToontownOnli
ne,
VegaS tr
ikeetc.hav
ebe enbuil
tusingPython.
3.
Mac
hineL
ear
ninga
ndAr
ti
fi
ci
alI
ntel
l
ige
nce
Machi
neLe
arni
ngandArt
if
ic
ial
Intel
li
ge nc
ea r
ethetal
ksofthetownas
t
heyyi
eldt
hemostpromi
si
ngcareersforthefut
ure
.Wema kethe
c
omputerl
ear
nbasedonpaste
xpe r
iencesthr
oughthedatastor
edor
bet
teryet,cr
eatealgor
it
hmswhi c
hma k e
sthec omputerl
e a
rnbyits
elf
.
Theprogramminglanguaget
hatmostlyeveryonechooses?It
’sPyt
hon.
Why?S upportf
orthesedomainswit
ht heli
brari
esthatexi
stalr
eady
suc
ha sPandas,Sc
iki
t-L
earn,
NumPya nds oma nymore .
Le
arnthea l
gor
it
hm, usethel
ibraryandy ouhaveyoursol
uti
ont
othe
pr
oble
m. Iti
sthats
imple.Butifyouwa nttogotheha r
dcor
eway,y
ou
ca
nde s
ignyourownc odewhichy i
el
dsabe t
ters
oluti
on,whi
chs
ti
lli
s
mucheasi
erwhe nwec ompareittootherlanguag
e s
.
4.
Dat
aSc
ienc
eandDa
taVi
sua
li
zat
ion
DataVisual
iz
ati
on-PythonLibrar
iesForDataScienceAndMachine
Le
ar ni
ng.Youcanevenvis
ualizet
heda tali
brari
essuchasMat
plotli
b,
Seaborn,whic
ha r
ehelpf
ulinplott
inggraphsandmuc hmore.
T hisi
s
wha tPyt
honoffer
syoutobe comeaDa taS c
ienti
st.
5.
Des
ktopGUI
Weus ePythontoprogramdesktopappli
cati
ons.I
tprov
ide
stheTk
int
er
l
ibrar
ythatcanbeus edtodevel
opuse ri
nter
faces
.Ther
earesome
otherus
efultool
kit
ssucha st
hewx Widget
s,Kiv
y,PYQTthatc
anbe
usedtocreat
ea ppl
ica
tionsonsever
alpla
tfor
ms .
Y
oucans t
artoutwi
thc
rea
tings
impl
eappl
i
cat
ionssuchasCal
cul
ator
s,
T
o-Doappsa ndgoa
headandcr
eat
emuchmorec ompli
cat
ed
a
ppli
cat
ions.
6.
WebS
cra
pingAppl
i
cat
ions
Pyt
honisasav
iorwhenitcomestopullal
argeamountofdataf
rom
websi
teswhi
chca nt
henbehe l
pful
invari
ousre
al-
worldproc
ess
e ss
uch
aspri
cecompar
ison,
jobli
sti
ngs
,resea
rchanddevel
opme nta
ndmuc h
more.
PythonhasBe
a ut
if
ulSoupwhic
hweusetopul
lsuc
hda
ta.
Her
e’saf
ull
-
fl
edgedgui
detolear
nWe bs
crapi
ngwi
thPy
thon.
7.
Bus
ine
ssAppl
i
cat
ions
Busines
sApplicationsar
edif
fer
entthanournor malappl
ica
tions
coveri
ngdoma i
nss uchase
-comme rc
e, ERPa ndma nymore.They
requir
ea ppl
ic
a ti
onswhicharescal
abl
e, extensi
bleandeasi
lyreada
ble
andPy t
honpr ovidesuswit
ha l
lthe
sefea tures.Pl
atf
ormssuchas
Tryt
oni sava
il
a bl
et odevel
opsuchbusines sappli
cat
ions
.
8.
Audi
oandVi
deoAppl
i
cat
ions
Weus ePyt
hontodevel
opappl
icati
onsthatcanmulti
-tas
kanda l
so
out
putmedia.Vi
deoandaudi
oa ppl
icat
ionssuchasTimPlay
er,Cpl
ay
havebeendev
e l
opedus
ingPyt
honl i
brari
es.
T heypr
ovidebett
er
st
abil
i
tyandperf
ormancei
ncompa ri
sontootherme di
aplayer
s.
9.
CADAppl
i
cat
ions
Comput er-
AidedDesi
gni
ngisqui
techa
ll
engingtomakeasma nythi
ngs
havet obetakencar
eof.Obje
ctsandt
hei
rr epr
esent
ati
on,f
uncti
ons
arejusttheti
poftheice
bergwhenitc
ome stosomethi
ngli
kethis.
Pythonma kesthi
ssi
mpletooandthemostwe l
l-
knownappl
icati
onfor
CADi sFandango.
10.
Embe
dde
dAppl
i
cat
ions
Pyt
honisbase
donCwhi chme anstha
titcanbeusedtocrea
te
EmbeddedCsoft
wareforembe dde
da ppl
ic
ati
ons.
Thishel
psusto
perf
ormhig
her-l
eve
lappli
cat
ionsonsma l
l
erdevi
ceswhichcan
computePy
thon.
Py
cha
rmI
DE
PyCha r
mi sa ninteg
rateddevelopmente nvi
ronment( IDE)use
di n
comput erprog r
a mming,spec
if
ical
lyforthePy thonprogramming
l
a nguage.Itisdevel
ope dbytheCze c
hc ompa nyJ et
Brai
ns(for
mer ly
knowna sIntel
li
J).I
tprovide
sc odeanalysi
s,ag raphi
caldebugger,an
i
nt e
g ra
teduni ttest
er,i
ntegr
ationwithv er
si
onc ontr
olsyst
ems( VCSes
),
ands uppor t
swebde v
elopmentwi t
hDj angoa swe l
lasdatasci
ence
withAna conda .
Codi
ngass
ista
nceandanal
ysi
s,wit
hcodecompl
eti
on,
synt
axa
nd
err
orhi
ghl
ighti
ng,
li
nte
rint
egrat
ion,a
ndquic
kfi
xes
Proj
ecta
ndc odenavi
gat
ion:s
pe c
ial
i
zedproj
ectv
iews,f
il
e
st
ruct
ureviewsandqui
ckjumpingbetwe
enfil
es,c
las
ses,me
thods
andusages
Pyt
honrefac
tor
ing:
incl
udesrena
me, ex
tra
ctmet
hod,i
ntr
oduc
e
va
riabl
e,i
ntr
oducecons
tant,
pullup,
pushdownandot
hers
S
upportf
orwebfr
ameworks
:Dj
ang
o,web2pya
ndF
las
k
[
prof
essi
ona
ledi
ti
ononl
y]
[8]
I
nte
gra
tedPy
thonde
bug
ger
I
nte
gra
teduni
tte
sti
ng,
wit
hli
ne-
by-
li
nec
odec
ove
rag
e
Googl
eAppE
ngi
nePy
thondev
elopme
nt[
prof
ess
iona
ledi
ti
on
onl
y]
Ve
rsi
oncont
rol
int
egrat
ion:uni
fi
eduserinter
fac
eforMer
curi
al
,
Gi
t,S
ubv
e r
si
on,Pe
rfor
cea ndCVSwit
hc hangeli
st
sandmerg
e
S
upportf
orsci
enti
fi
ctool
sli
keMa
tpl
otl
i
b,NumPya
ndS
ciPy
[
prof
essi
ona
ledit
iononly
]