Uploaded by Vivek Krishna

PP UNIT I

advertisement
Pgthon sogsammng
ourse 0bectives
and Caeat
mantin
Se
and
Leasn Sytan
Fwnchona O
Rhon
Hande Stslnas and Fler n thon
Undestand
expxessfona
LIsts, Dichonaefen avd Kequlas
n
thon.
Implemet Obiect Oieded odgramma
Concapt în Pthon.
Buld KWeb Sevius and thoduction to
Netosk Qud Data base psvasamming n
OIT-
Tchrduceten lo hon
Rhon
a
FosSum
and Compule Sente, Jelkslandi .
Ma1hamadica
iko
*
developed by uido Van
Insdhats
Reseasch
Nadfonma
oas
woa languay
uthon sdeived
C, C++, Usis shell etc.
Rithon is
*IH
f's
a
usea
hgh-
a
00
anguagR.
open Sounce lananae
Pntespoete \
Code
Sowa
level pooqramm
in
to
o
Convesting
mackne Code
0fente
an
and
* suppoa psocecore
D8paamminq
orienled
ohfect
Seadable
ts
kiahly
*Rthen laquagr
-
usea
EalRsh kauuoo%ds
* hon s
Pafthon
Ptkon
and
.
Case-Sensiftve n natws
Contains
useul
awbmatic
deelpig
gasbage Collecion.
Web
appleationa.
hon eatusA
high
Jthen s
thom
a
level
oaMming
T s eAatlem to lea
obsect
obie t osfeuled
povqsamnüng, poDtacuusa psoqsawmiva
pobvidea
aDaches.
follouong
pyton.
nauo
g
suppo
ane
te
dunamic wemoxy allotatt
exential fealluu
KThon:
tCode
ohtn
Cod ohen
and
leain
to
s
easy
eas
Pthon
to olket popqaamauiua lanouagen.
cOwposed
wuch
Same
ad
Enalh. No sedcolon &ux
bsackes
T mCpenSou
fs
an
dlouonloaded
and trec
opem-Souo
so d
lanquage
Tt
Can be
be
I t Ca
and
be skaied
Cast
Can
Supcat Objec Oxrded
fhon
0bienlad pDqsammi
Suppod ckiet
fealuan Such
aa:
obech
Classes
encapsulation
innetants ett
)Postable and Pladfoaw nde pendeut:
Hthon fs potabe
n notuu..oseovea, luthon
Cod
tn
Can
be u n
any
envisonmeth
ka
Oindows, Lnux, wac etc.
IteqsatdLanguoJ ge
V
Pthon Can be iteqaled witk olhau lanque
JO
Such aa ,
Ct+ ett
vLxtexpseladLa
rtThon
usex
Sowo Code o
Purthon Cooe s
be come
an
irter paetes
o convediq The
macdine Coole. whi meane
exeuta e
eas to debug te
by le. Hlee,
and sole
Vi)Huae Stawdasd bxax
thon has alakge umbet
heCordtain
bsoves
psedelined moodules and uncdowa
coxtain taska. Moxeow, lbaasy s pstable
and
Csoss-plat1sn Covmpadilole
vit)ravfcalllped:
.
not be
nead
Vatable
pfhem tupe
I Pyhen
od
tsel,
detider
Intetpxder
delfntd.
Sn-4tne
Scalable
Python povides acod Suppt 1 lakge
SDasamS
awell.
xSuppol KUI PSDqsammng
o
vasious UT
Cveadtia
Suppils
Putkon
Pthon
appliaona. I t ha mooules ke t s ,
& Tk thabugh wkich
Pthon
C4,
P
qaphita fndealaco
a
Calad
Thon e
ution Mode:
Pylhon pavqaaMmng
not sequîsed. But a
is
Sunfime Stxucuxe
ython indeu
Kouolecdap
kasic undastavdina
SnecoMasy to
Knou
PDCCM cpapaam enacutian
PVM
m-pC
-P
****
Souno
Kuntwme
Bute Coole
8)
Puthon
Rst Py
Sougte
Pyton
Compiledle
-fis st pye
101010110o
110O110)1o
Machine
Bu Cooe
Compwo
Coode
ode
eneuom mool,
n
st
Souste
Compile usng pufhon comilee.
a
Byte
Cooe. Thea
1
b
- Coole
cod
genonales
ho luad Machine (PVM) +
uStna
using
genekate
a
mackine
PVM is
Cod.
zntime engene
PVM tesalen thaough h
me -bu-one to
hon
bate-Code fustrud
Cary out th opesotione
ttoms s Chetpe
But n
obet typea od Sywtan used thon
ss shouon in Table. Evey ttka patwMed fn pyttam
poDgsawM is a Kend
olseet
Obect Type
Exawple Lteuh/Cxekan.
Nambets
34, 3.14-15, 3+4
Decal, fsation.
Stavs
Spam,Naiks", bahxdic'
Li'sts
1,5, ['te,
1, spam, a,'u, 3:s).
Tuples
DPchionasiesa
Flea
Sets
Ofas Cose types
Fstqpam Uhit types
mplenentaton
velotad tupe
manqo
:so, aste yump
myile = open eags, 3
set (nbc), f'a', b, e'.
Sooleav, tupes, NaN
hunctomvA, Nodule, Classes
Compilad
cocla,
Stack
taacabacka.
Fmstant) to pealAm
text
patlean
classes
ase
use
scsfpt+ng
netuovk
Such
a
Oofectn
n
wftk stale mant
creal
matchiug
and
patfean obfecta
socket
cbiata
unchons, modules
tm.
T
aa
a
Creaed
epses&ona
de
unctionu
Class
clam
wpo
ambda.
Psntive
Standaao Obieet lypes:
evey Thinq
O
SPns
SPnt
so
an
poDte SSed
obiect. Heaa, dadu
in
Hthon
ypes
ane
PodgaamM
prsoqsam
actually
classe. and Vaxablea ak instane(object)
clas
ses.
standasd
ox
) Numexfc
) Sequente lupe.
built in dada tupe
Plhon
1) Soolean
iv) Dectfommy
v Set
Pomitive
Pathon-DataTapes
Boo lean Set Dictonary
Num eaPc
Complex
INumbeu
JSequanta Type.
Stings
LstTuple
Standard
type
pytton,
Yene
ente cxeadng Fucteges
nudve nstaudiadion.
and
ae
not
sthfhg
classea.
olkea not
Othe Bult in da-lupea?
Iadden to standaad datatypes, Pthon
haa oltet
bullt in dadatupez
Tha aAa 12ted
Thosy
llows:
) Type
1 NoneNull 0biect
1 Fle
iv) Functon Mefhod
Module
vi) Class
vi Class Tnstata
Tpe)
type () buftî unetion takes obiect and
Setuwn ts tupe
Tha xetusn cbject fs type
a
obett
ye (obect)
tupe(a)
>int ype
tpe ("Hello Woxld)
ctype stn
4tpe type
) Nova Niull
Pithen ha
a Special obiec knoCn a l l
obiedt. 11ha only
Vaue =None
ons
type(Nona
Null
obiect
do o
Nonc
have
buit-in unhioms. Non
ans
aluoys evaluale
it) Furdions:
uncticrua ase is
any
har
to hae
euos
no
atbues
false Valus
a
nteusled to pexld&m a
Speuic task. functoun
Can
etusn
def abRon (a, b)
C a+b
setun C
addihon (10, IS )
a
Value
Itevnal
Data
ypea
Irteanal data tupesused n t
axe biel
shouon
Rthon lana
hha
* Code
*
same
* saceback
*
slice
*Elipsis
sange
Code obfect
is
()
Compile
u-buftfncton
when
calles
code objech oaa Cseatas. These ae
executalble pfecos
Pthon that asebuta
Theae
obieds a e appropråte
Cxacudion by efta erec & by eval ()
)Fsame objecta:
Compiled.
Sepsese
n
exochon statk rame
Pthon. IH cotain alnmaron Tk
Python ntespreleg heccda to Kiow du
duina
Su ime enocutriey
Ye
Stults in
ame
a
obiec
new
C
a
Call
mcton Cal!
aame obiect and l eacdh
Stack aae 's Cxeahd
ach
i) Tsaceback Cbed
J
Cxto pion is saised when eos OCCu
Thon.Texcoptioma a
handled
Rnlaspselas
exits
Tsaceback (innesmast last):
nOT Caugtor
o
wmesso.g
Fle
in",
fne N?, n ??2 Exso8Name: exzor KaSon
) slRa cCbiecta
J
.Sle obed ah Crealad using
exterded slite Sunta
stside indeting
mut dfmensfenal vdenun.
:c)Elfpsis îndeat
Seguence., stast1 end 4|
Sequence Staat1:end1, Stata: enda
Tuhon
Elipsis Obieda:
extendec
in
used
These
aR
These
Sequnte
Stat1 : endi
CIlitpsts olje ets also kaue a singlo
Ellps's
v Xsange
and
hae
a
sle notartian
nama
boolean TRUE a
imes.
Ol
i s Csecles usfin arast sane ()
Sibla
Sange C)
It s
used ohen memog
slfnte
SanaeC)
aeaale
a
lanqe
lata set.
Standaxo lupe pekatoxs
aValue Compaxisoni
Compasison opeRatoss a
equality
two dlata Vaucr
wed to delorwie
Cchpaxison
yytelds
ielals
TRUE os FALSE Valuor
opeicdors is ire
opeaduss
evpx <
Cxps
List
uncrcn
expsa
epr
expy
is les than exp-
exp 1
s
grea
Hex1 is less than
epx1>= expo2
epo
ep
exsi
d Comporian
expr
ox
cqualto Cap
is qveaa a equelto evgra
is equal to eup.
ex1 is not equal to eps a.
Elamples
.q6=8.33
S+H4>=-3
abc= xy2
abc
ta cpra
y 2
abc
2
3,'abc']== |3, abc
bTdentits Compasison
Pafkon Suppta dinecthy Companng obiect
Thamsehes. Obacda Can be assiond to
otkes
(by selsana)
Vasiobles
EMaple)
oo1
to0
=
4- 3
Seante te
Same obiect
Exaple
oo1
Soog dieclt
= 43
ooafoo
Tho Sama obiect
3
Exople 3
Re)ponte dnpant obect
foo
= 4-3
fooR 3
+3.0
Foo1
quo shouastoo d'sRnct
Though bot chjects have
O04
i Goo)
dfeca)
inkaa& neated usnaSoolean
and, 'or ad not. The
ase
logfcal opesadia
opeaato)
ha
Opecos
not ep
and epsa
ahert paecadonca
wnhio
Logica NoT expr(ngadin)
Coica AND
eupoa
expoA
even
Vauua.
43
Eupressfona
expo1
SaIme
4 4-3
cBoolean
not
obed
obiec
eapo
And
(onunchon).
Logital OR
exps4 ug expo
(lisfunctn).
Exaple:
not ( < S.o)
(xe s.o) 6%y>. 718)
<s-o) and (y&:718).
Staundasd pe Sut-in-Funchana
Along
Alou
with
qenerie
Phm ao
lhom
opeactoss
pxbviolea bult-Pn. }uncfiova
ha Con be
plid
he og
applRd
to all basie obect types
Cmp)
Seps)
stsC)
*typeC)
Operatiom.
diaM
Cmp (olk, ola)
Compares
and seruan mtesen
ohisoba
chi4obia
cb1= =obja.
epz(obj )
"d
st
etusns evaluattble stba
sepsetedaios c
she (ob)
setuana paftale sting
sepoe sertatton
type (olg)
«
Deteaia pe
objand
setukn type objeet
TpeC
t
n- unction nhon
bui
a
setuana ype
t
okiect
satype (objet)
ype (4)
tpe int
»type ("Hello Oosb")
< type 'skinas
tye (tyeta))
type 4upe
two
ompalos
obeet and
setusna
teqer9
a,b - 4 l a
Cmp (a,b)
Cmp (b,a)
Cmp (a, b)
ab
abc', 'xyz
Cmp(a,b)
Cmp(ba)
1
a
i) stx()
Sts()
ad Xepx )
and seps)
nctoyma
opekato (
Sepse sesntadon buill n
& sngle back & xe veue quote
quote
J
) a used to xe-Cxeae an
ooject thsouah evaluasim.
st (qS3 -a
sis ()
sts ([o,s,9,9])
sepaCo,s,,11)
[o,5,9,9]
qS3-
o,s, 9,1
o.5,9,1
[o,,,
Staucdesdype Opetatoxs od Buitin-dunt
Opekcbs
FunctoM
Deacihiorm
Re sud.
stiae pxesentaone Stoing sepse tentate
ste
Burt n funchon
Cmp (obja, obja)
sepr (ob;)
st (obi)
type (oli)
Compas ho objetn
Sting sepxesestadom
Str
*
Deteien obied type
tupe
i) Valuo Cowpaxisona
len kan
gseaua
h00
lex tta ox cqwl to
b00
great
Ohec
Copaisoa
s
snot
ar d
qual %
boo
qato
b00
not equal to
hot equal to
boo
Same
bool
aa
boo
not the Same a
Boolean Operadon:
not
and
logica negaion
logeal Cojunchim
logcal djundn
beo
boo
tho Standosd
Cateqoaizîng
The
hoe
Yeladionskip
modeto Cate qoiz
Each moca Shows 1
typer.
Standar
ae a
oliHelt
thsee
as
lypes
bethoean tke
ypes.
Te
molelh
+ollows:
)
Storoge
mecel
i) Updat
moda
in) Accos modal.
all t
Te shous
dexet
meodel
Dota lype
utes
tupes,
1% categonttaton.
Stosage Mooe
stavalasd
Threc
Accen Mod
Upeat Mndes
.
Direct
Scaak
mmutalble
Stongs
Scalas
mutable
Sequanta
Lists
Loroaned
Mutable
Sequanls
Tuples
Containe
MTnu tab le
DIctonaes
Containe
Mutable
Numbers
Sequene
Mappir
Stosage
moole
isst o
sst0
to Catecpsiza t
many obfet
An
can
be stoses in
an
atomic
Single Rtesal object
how
obect.
oo
Scala
Stala
stoso
> Condaina Stosag
CCompesite Compound
obiect
MuHiple obiectn
Ptton pe
stotage Model
Scalax
by
is
wkich hos
objecttupe
*
tupe
Numbosn (all numuic tyen)
atom
string
(all are lteaale)
Rsts, tuples, Retionaries
9Cortaine
Sstha
ou
Self containedteas etawe
ython doe no kae a
chaxactet tpe
"Python"
SPylkon
S
so)
s
[o)
P
=
"T'
Cor
i)olata Model
Anofket
by aslang
way
to
Cateqore
standardtypen
Onte
Cealad, objei be
ouestioa.
changed/updatkd
R thon lupe
Upaede Moe
LAsts, Dectienasics
Murable
Numbeta, Stings, luples
mmutable
nmutabled:
Pyhon numbeu and Stsing
=
=
ase muctalble ?12 what ive?
id (x) 2 8
»id(f) etk
Mutobles:
ammonia', 83, 8S, lady
8S
A)= L[a]+ 1
L)- "steco"
»append ('candly
appewd
+1)
n
Accen Model:
Accem wmodel helps
to
aciom tka
stored data. Catecpsos
Vauun
aCcon mode a
Pthon upes
Actwn ode
Disect
NumbeA
Sequante (slia)
shings, lisk, fupe
Mappi
1fctionaien
In dichoraaiea, elamath (Valuwn) aki' un-o%clesacd
and
accOMed
Mapping types
paiss
with a key
a
set
his
This
akos
hasha ke-Valu
Unsuppoted ypes
Rst fupes fhadt a
T
not suppAld n
O
Patken a
chax
byte
Puthen
byte
do no hawe
chos
a
to hold tu singa cholad
8-bit degea
) Pointe
lhon
NO
t
nood to
manages memory, Ioe
actos
obtodn addses
poinlo addseea
use
obiect's
Ts
s
0aoee
olencht ty. e
idc).
i) int Vs shoat Vs long:
Pthon's
plan teqera
ake
The
integer type. Use ony a
Singe tue, Pthon degeu when Compaled
wi c (int, shdty ad lona).
Uivelsa stavdad
f8 example, utplyng hoo lage nambers
rthon ves a long back insteas
ovekouoro
with a
ed.
) float
Vs
Deuble
Chas bólh single
pretsfon loat type aadd
dnulle psefsion 'eouble
tpe.
=C dosle
-
Pythen'sAeat tupe
P then loes not suppt
floccing poit ype.
a
Singe pae sfon
NumMBERS
Numbera ppvfdo Scalas stoxagp Gnd dkvct
acten. Numbe
ha
Serehal
Tntee
is a immutable tupe Thon
numai upen
gena
31
ta-1):
Plain Indages
Long Tntegea (Supeset oYotee
Boolea
Exomples:
h e x a
Lteae
OlOl, 84,-234, Ox8O, 014
Ox 9&
Iweaet
16384
Poan
Ox 4-E8L
OS144-36+L,
,
-680
-21474836422
91794-S8A
OcDECADEBEAPEL, -S432lbla34L
and Falke
Bool ean
Nambesa
at
FHoadig
Psec?sin
1) Double
Floaing
detimal
pont Nalues a e chdD
point (-)
sepxesendg
and
an
denotes
optionas
ScfondiR notation.
u
e
by
"suH
Exanple:
2eS
-777.
00
-90-0
3.14-16
-1. Go9E 19
42E-10
9.3B4e-13
6 .09ea3
-S-SSS 6I19.
omplex Numbess
Combiuirq
a
umbea m a
Eaanples:
sca umber th an imagnaiy
enh
a
noon a
64-375+a
93-g.S
G-3341-
9-8066-S-243-I3
X
O 693+1S
693
a
O p len urwbe
ma
a Coniugato ()
63+1:S
0.93-8.SS}
peiafina a
Mited orle
PTen Suppdts mied mode perakina betuen
numet
tpe*. ie
add nteqe and lent.
(2+ l3). thom Solvea te poblem usirq
"numeAic coescion'.
fs Comventeto
Hexe ono TL opexarel
olle opeAdundupe
START
(wfth bok
nuwbe
ER
No
NO
NOlong/
float
omplex
/ERkar
Yed
Yed
Botk
/otk
NO
NO
NO
org
floa
Conplex
ConveRt
non-Complex|
Ys
to Complex
Convet
non-ffoat
toFoat
YedTonveT
on-lovg tq
long
-
ey&m tke desîsesd
nameic
Qud STOP.
Coptatian
A mati
easie
nuw.elic
becauge
no
Coexcio
Con veekion
dathe. qlhon pmoviele
makoa
prDqan
is seqwed
Coexce) buit in
nchin
Ex
Automahic CoeRcion
Add itegek und'foot
1
+
0+S
SS
Plocod is Supextet)
OPERATORS
Numetic
thpes supt
gg Aom
Cxeahom
stanclosd
opeAat6a
Vaaieta peradbiy
teopeaoba to
wio
specx
numbers
standa ypeCpekus
Standad tpe opeatka
weaic tpea.
t compaxer
\ al i
Valuo
wdk
ft
to dota tupes and setuswa TRUE
ExAUNple
os
FALSE.
S ==Sa
-719> 233.
S+4-e>= 2-3e
(a&s) and (s<9)
77>6 = = 66
(77>66)
and (64=60)
(-I<) ox (1<-1)
o
A x i t h m e t i c OpesatoxS
Patton Suppåt
loth
Unaxy
opeaad6a
neqaion
no
Such
aa
chag)
LBinasy
+
aExponediation
*
l , %,*4,
S useo
eponotianon.
3
-3x
4-0
*-|.o
O
-3)x *a
6leosDvision
/ i s USe
fcos divitkenopelake
T
tsuntales teaacRon and souda
t
heat Sunale st ohole uwbe touond le)
t
uwbee
faaples
1-2-0
cModuls| Remakdes
dpexados fs wsed
Eaople
modulut.
8% 3
7%
1
72% 3.
0 79999
103
& Cat be a qsDup
3
ity Bttuoise Operatoss
Fton abo SuppA 6toise OpeRotdar/
Invsfom, bwise AAN, OR, XDR, let and
Btofse Opeaator
unchon.
num
Tnvet bit u m
num1
umi
rum l t skitad by u
UwMa
umi & uma
Mum 1
um1
EXolest
num 1 bitwise An0 it numa
numa
num1
bitwise oR wsth numa
num
num1
XOR
30
45
O1110
101 IO
I
O 0
3 0 & 4-S
30
let sliltd by nuw
4-S
S&G0
63
44
oftk Nma,
NN 30
I
4-S
0
60
IS
O0
304.S4S
SI
30
=-(o1 0+1)
11.11
31
>
N4-S
=
Oli0 1)
(1o1 161+1)
(10
0)
Buft n funcAba
Standasd Tpe Funcde
Bullt
Aunchins cmpC), sts) and
TypeC) as ppled 1 all standasd tpe.
numbesa, on
unetiona wrll Compas
wuw.belA, ComveAt to Stainasand predief
tpe
umben sespetivey
Cxamplee
Cmp (-6,a)
Cmp(-4-2
331,-2.718 281)
Cmp (0xFF, ass)
O
st (SS3ea)
type (oxFF
ss30.6
tpe n t '
76Sy 1210 L)
21018
(98H6s43
tupe
<type longid
type(-1)
etype 'Coplals
b)
Nuwe ye Functova;
Rthon
Suppdt, d}exont set ouilt fn uvbt
wwelic
Soma Co vet
tupes
type to andlkes whil
peua
Soma
Esanles 4
on velsn8
numge
othota ao cpeaadiona,
alulasitna.
pe
numelic
on
pe
Convea s fana
fat (4aSSSs)
onaomga-a)
Hoot (4)
Complea (4)
q-+0
Comolexa4, -8)
.
Complex
. -8
(a-3e-10, 4S.3e)
. 30-10+YS3O0o
Opexotiomod
tton
ho Ave operafional built n wncta
iabs)
Coexce )
iit) dvmod()
fv)
poutC)
V)
sOmd ).
absC):
CxAple
abs(-1)
absabs(10.)
abs (t -2-t
-2421)1:2-2-1VI-X1 &
CoeRce C):
Coexe
Coesca
4.4
-
2-1X2:-1X
+4-
(1,3)
(L, a)
l3,134-L)
C1.3,13q-6)
Coeate (1, 134-L
4-, 134-L)
Coekte (4,134-L)
(1, (134 +01))
Coence(toa3-4,134L)
((1-23-41),taq+o3)) .
divmod
ombinea divison and maoulus opesa
wnction
aud setuana palr (quohut,
semainde).
divmod (10,3)
divmod 3,10)
(3,1)
o,3)
divmod10, a s)
(-0, )
divmod(aS,1o)
(0-0, 2.s)
)pouot
powC)and X
peum expont
adkon
poo a, s
3
pow (s,a)
pou
2S
(3-41592,a)
9-869%60 a1446-
poo(1+1j, a)
2+2)
Sound)e
Inosmalysownda a loctna poit nuwmbet
to tta ngak AtttAlee nteqra! numbe nd
J
sesulta
a
a
dloat
Sound (3)
3.0
ound
(3.45)
sound
(3.499999
3.0
3.0
ond (3.4199999,1)
3S
EE a
IEE
E
O
Sequente tupe al shae SAma altom model
ie %deked set uottk seqnoutiall ndexe). ffause
shows
houo sequente
elewonla oveStosed and
ac oMed. Numbeing schehme stals }om Zero (o)
1
-2
N
D
Seqente
N
-N-)-(-a)
'
-
1
Ne= lenqih Sequonta= len(seqwent)
U
n
a
Sequene
bu usng
slie
ultiple elemont
aaselecte
operadoxs.
Sequovo pe Cpelatoss:
Sequeto opelatobr
Fwntin
located a naex ind
Seg Cmd)
Elemeut
SaPnd1 : inda
Elemela o
Se*eapa
Sea 1 +Sea
ob in seq
ob nst in Se
Sea
o
Sea
fnd1 but not
incluce nda.
epeala ex
tmor
ConCatenabs sequSe1 s 2|
Testk t
Te
obj is a mensbes s e
ob fs no a mewbe
Sequento
Mewmbea skip (fn,
not
fn)
:
Memberskip test opetadox a i usedto
detewine okalhe an elkmes Ps A i a
Membet d
Oe
sequent. T
Doolean in nadwAe
ob not J
in
and not in opeed
aud aetu Tsue |False-|
segunc.
i)Concadenadion(+)
I
allows to onto0 sequontes
The
ype
Sequena
+Sequana a.
ti) Repeto(*):
I fs use)
hen Conse tudie Copren
Sequeunte elamot ako alesfxe
Sequonte* Copies_int
itege.
Hello S
Same
sktesti, [:1, t:)):
Sequontn
tn
an
ae
datu shuchus
cosdetuo
manno.
tad hol obied
Slie
a c o n ndvidua elemau
ad pai
bsnckob
Sequone fndex
Can
to
be med
nde
Stings
Stings
Sings a
sequonte o chasa ders enclosed
n Single ox double quotes" "', Shings alo
iMmutable.
Via sliing
shin
Stinas aR actomedseqondall
Sh
-equlas shig (str)
Uncoale
Cseat
Stangvnicoda
Assiqn Stiq
Cseating
sts ) unhion.
Ea
a
a
stng
and
Hello
s
Smple &
assqn t
orld
msg Pthon
paint (msg)
is Cool
S St (sanael4)
o, 4,3, 3
oa
wse
t
Variabe.
i) Accem Strina
To
tta elemenla
a Shing Use
bxackal [] along wih The
altes
ka Squase
The
Inalices & hdex to obtan Sub-Stin
1234-s 6 8 1
a
Hello Woxlo
H
a [o
a [i:s]
aL6:
ello'
wWoxlo
i) Upelak St
An enisRa Stsing supaatad ba
e-asStgning a vasable. to OUolher Stag
stain
Hello Woxld
a-neu
a:6]+ Pathon
bdPaatstaing altogeltat
iv) emeve chatadey
Shina
stings
immutabe
aAe
Cannot be semoved
So
fndvianal chasaceu
om an existirg staing
To dsop d rewove one chaiatae
a
Hello hwoxld
aal:3]+a [a:]
a
Te
clea &semove
a
Helo World
Stain
e t y shing
de a
delee Stia.
St
and pexatoxs
)Stonsax ye Cpeadoxs:
A
to Most
Exaple
Opekatoxs that applt
Ppli
Umbe
nclded
cbieda
aa
a
abc'
b
standad type
mn
C
a
in
xyz
b
b C
)Compaxd
usinr
Asci Val
a<Cad b=*y2
Ordat.
false
Methodse
n
Buslt
>Staing
Stsung me1koos add new unttinalit
to
Stoivng
a
mooula.
Descxiptron
Method Name
Sthinq. Capitalzet)
stoing slouwex ()
a
Copatali Ast letles e, si
Retuswa tsue
han atleast 4: Cased
pyhon".
shing. isdit t)
chanactes and all cosed
chaiodlen
a
1234S
stsing- loues ()
ahe
louwes Cane.
-Retuaw taue
sting
ondy dits
contain
Sting isnuwerict)
sttr
-Retuatse
Sting-
Contain ony numeic chasala
-Conve a
uppe Caae t
owel Cane
String uppes C)
Convela
looes
CaAe
fo
ppe Cae
stia ttle C)
AU wOsals beqin ik pe
Case aud sest ao lowea Can
Stsirg suoapcase)
Pylhon
PyTHON
sting staip ([ol))
a
py lon
Tnvert case 8 all lelleu
n
stiv
Pexyama both Lstipt)
xstpl)
on Stoing.
ad
Stsing sipC)
a
1/
Pyon
Rewoven all toailfn
white spate ostinq
stsivq-stipt)
Removea all leadina
iote.spates n Stin
stsingisspale
Retusna Tsw
Pyn
a="
contains only white spale cha
stinaisde imal()
a
Ret
sthirg.Psalpha
()
a= Pythn
sthinq epanata bs (
shina nd)
a
Retusn toue
ateaat
A thasactes a
alphahenic.
Pyfhn puasa Mir
a.ends sih(" fnq")
a-nd ("s")
J
stinq.fnoe
Tsu Stina
Cotaln only deimal oligg
laSS
stn endsuoYlh (
stina
).
shing encode).
sthina Cowtes )
Stong Cot )
Stoina exdeud )
a .index(y
Q.entoca C)
bpyten
a-cextes(10)
sPyke S
a.
Cot"P")
LISTS:
List aso psvvicla Sequendial stosage 1hsuh
Rst a lcom can be Singla 8
an inoex
.
Conselutive
elemenl hadug shea
listnchce stavaard
Lt
uset delied pe.
Soxted and evelie
ephy,
cbct phad
types
Cau
O
weu
a
ePopulatad,
Lfst s
upalalad
mwtable
n
.e elamont
Con
be nseslas
& semoved
Cseota st:
Rst is simpleLists a e
CoeatioM a
use
baackata
&
delimted by Squae
hcton
ta
List().
183,
'abc', 4-S6, 'innel,'1st
9-13,(,1,10)
ewyoty ist.
st (python)
i) Accem List:
is doo usin Squar
Lfst acuM
aud nde. Srtla to
Ex
boackol
stina aton
3
U:
'abc', q6, Linnea', '1t
ia3, 'abc qs6].
Lst
i)Updat. Lh:
te m
and
suppdt
mutable
Sina 1Pst is
witk
Elementa Can be addea
assianments.
appevdC)
= 123, 'abe, ['inner, 'List], (7-93)
L
abc
1)-4-S6.
(?-1j))
'Lis],
L'innes',
123, 4 S6,
T
LstLst Sequen e Opeatoa:
ska (C) <[::]):
a 4-3, -I.23-a, 6.19es
a)
-
a [:3
Q3
23,-2)
)Membeskip (in, natin)
40, [4,), tet', (-1-1+63)
a
text ia a
in
i Centatenchat)
43,
la
-I.23,-2, 6.19eS
[a-, (a, '], 'text' (-L9+4f)J
=
tal =+ l
tutl
43,-1-93, -2,6-1ges,40,1, \«I, text'|
i) Repektton (x):
=
-1-9468)
4-3, -l.33, -a, 6.19e S)
4-3,-1-3,-2,6.19es, 43,
-1-23, -2,6-19es
ist
=
[
My naye
Pthanm)
List.append ( I aiv
to
List My name
am rnous
Remeve List
To
To semoie a list eft
Use XemoveC)
s KoOn
exact
t
e del statemest
elamaud to
be del.kd
183, abe', 4-56, innex List,(7-93)
del
L1]
Semoye (123).
del
exprtirt semoe Cnde
>
List Melhods
Lists fn pylthen hame wmelhoda. Some exa hoples
Vaious lst methcada asa
) list.append (obj)
1,3,34)
oppends-(a,2,3,45
i) st-count (ob)
Count
i 1st.ndex (obj)
G)
1.
del)
>3.
tst.însest(indea, obj)
Linset (4,S)
v)list. veiave (obj)
>
Semove (Ss)
vi1st seei se (obi)
viList.pop (obs)
xe vee )
S,3,2,)
Lpep
vi I st. sost (ob fumcion)
»sost)
ix)1tst.etond (se)
extend (" H")
,,3,9,"H; "7"]
luples
Tuple
Condaina
anolThot
a
tupe similas to
tuples
C) wle
ists Cly daleranta
is
as st use L 3.
uplea aa immuctable.
Cseat
wse
a Tuple:
Cseading
a
is foletical o
tupe
list,
enclosed n ta elfitiog pasenltae s ) .
t = (123, 'abc, q.s6, L'innes, tuple
7-93
(8)
4,,3, 45, 6)
tuple(L)
=
Accem Tples
To
altom
bsadkats
elameilh
slia
in
a
opetatoa
tuple
use
Squaaa
alonq ndex
t=123, 'oabe, 456,nnex, tuple'), 7-1)
tL:3) (us, 'abe, S6)
14uple
tuple
ipolate Tuple
Tuple aRs
ww.ta.ble. So tuple dn not
Suppot update &K chanap element Values
t , t l , +l-1
(123, 'a be', (7-95)
ta(12, 34-56)
ta = ('abc', 'u2)
ts +t
v) Remove tuple
(12, 34-,
abc,
Rermovina nlivoluaTuple eleme
nTpessible. ExpiaH emovee
tuple use ole stataman
del t
an
'ay2)
is
enhRse
uple
Sequento Opeaadnxs
slke (
:):
t
xy, 123), 3, -103.)
to]
ay, 122)
t h : (23,-10 3.4-)
1) Membeship ( fn, stin):
t= ([xy2', 123), 23, -l03-4)
3 in
180 not in t
Concatenation (+)
t t+free, easy
t=xy?,ia3) ,a3,-103-4, fseu, 'easy)
Repektion (x):
t*a
l03.4.
1a3]
33,
[yz',
-103.4,
'xy, 123), 23,
DicTIONARIES:
Dictiomaies an a Pthon's inale"mapiug
ype T
s
mutable and a ovdainet ty
tkat Can stose an numbet
Mapping
Rth
e
a" keu
we
ohes
value" s
obcta
olet tupes a s ke
dIacty mopped hana
thetexun wa ppinpe
The Suctaa d
Key
Cxcat
Valua
a
and entsies
dichonay edog
ade
enclosed
Tbaaco
a ctonasiea
Assan a dichovay to a Vadiable, seidlen
whetha dicdomory has elanianta & hot.
d
da
name':'earlh, post:8o
da, da
name':
'eaxll, post':ec)
ti) AcceM
DicKonavies:
accom
eKe
along
alona
ele menda d ditkonaryuse t
wit sqak bxackeki
daname'
C3,
eax th
Eror, bco
>
not
pat
dichionay.
da.haskeseve)
o.Pale
DiAno3 cnande wta kes
ds
ds[1
'abe
d3L1' =
3.14HS
d3-2] = y 2
d3
d3
abe
'1': 3-141S
'abe,
1:
'ay2',
3-2
OpclateDctinase
addina O
by
updalod
dtiona 's
pai),
leC-Valuue
(i-c
&eloment
A
a
Cadxy
now
moa
&
delcte
an
enisting enty
daL'name'
=
yenuus
da L'post'
=6169
un.
da axc'3
i
Kenove
Drckiva&Eleailh
Entre contes
eleme
Can
cctonaa&
o
ae
b
de danaw
da.cleC)
de di.
Semoved.
navidua
fctiona
Methoobs
built
Drctionafes ao have
1 d.clean C)
) d.copy
) dValucs C)
) d.keus C)
v)tems C)
in
me pds
ewmove al elanasts
o
dkionos
setuuna Copy
dRona.
vetuwws lists ot, dichena
Yauos
retu lst
setuwe
ditional
(Key,Value) tuple
pads
vid.han-key(Ke)
vd.updat (da)
setuva
1 .
key nin
dichonar
ado Ke Valua pais
to Ik aickenas d
Download