Docsity

String Manipulation in Python, Lecture notes of Computer science

Toggle sidebar
bg1
elassmate
Date 22/9/12
Page
STRINGMANTPULATTON
Ihroduction
HStcinnLiaanarecharacdersenclased
uiaia
singie
uaies6
dauble quaieshestcin4s
cre ionkaudalale
cadaHpes-stinghas tciting
indexos0andlasis
hil
lenh
Lsicin
Ccn oe starled oerelerred
otoraarol
nidexiag
hrouok backiuasod
indekias
raversinqSing
Ever indisidual
chasacier
oiastring
islaccessiale
Hhouaa
the
uniquendex
coi
eadhdacsacer.
Uslin he imdexesae
Uner cca
Araverseastinq
charaderlay
charaderrarecsi
reters
o
Hertino
hroeh
dhe le
uesotheshaing de hero.cder
atadine
Asirina
conhe daver.sed
tik
Aoruiareoorbackuaid
aa
odexing
or
wLd indexing
Clndio
-5-4-3-2-1
Ao in ndia
prinili
OR_pcii
end2)
backwas indexin
4
734
ndia
5-4
3-2-1
lenCc)
toriin
range
-1,--
princ:).
OR
dor ihronge1 12-1)M
priniCeliI
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download String Manipulation in Python and more Lecture notes Computer science in PDF only on Docsity!

Dateelassmate Page22/9/

STRINGMANTPULATTON

Ihroduction

HStcin (^) nLiaan (^) arecharacdersenclased dauble (^) quaieshestcin4s uiaiasingieuaies^6 has cre^ ionkaudalale cadaHpes-sting tcitingindexos0andlasishillenh LsicinCcn^ oe (^) starled (^) oerelerredotoraarol hrouok (^) backiuasodindekias nidexiag

raversinq (^) Sing Ever indisidualchasacieroia (^) stringislaccessiale uniquendexcoieadhdacsacer. Hhouaathe Uslin he (^) imdexesaeUner (^) cca Araversea (^) stinqcharaderlaycharaderrarecsireterso Hertinohroehdhe (^) leues (^) otheshaing (^) de (^) hero.cderata A (^) sirinacon (^) he (^) daver.sedt (^) ik dine Aoruiare (^) o (^) or (^) backuaidaa odexing orwLd (^) indexing C (^) lndio-5-4-3-2- Ao (^) in (^) ndia priniliOR_pciiend2) backwas 734 indexin 4 ndia5-43-2- lenCc) toriinrange-1,-- princ:). OR dor ihronge1 12-1)M priniCeliI

elasSMAte Page^ Date

Strng Opetctors

Stinamanipulafioncon^ bedalseinmuliplewaus^ laelhasic OpercrSuAed instrinaretandkdnd^ memberslaip Operator inane^ nalin lheopetaturpercormS^ concatincdionahere^ aperotor petome repli.cationrepeatitionAsstrinasoureiuablehe inputshingscannat^ he^ noolitedhut^ he^ new^ strinasCon^ be

creded layusingalread prese stiings

Veeru:dayleeru "2 "12" 2+ 35 (^22) Ertor

The userconnot conlainea nunioer ond a sttinoS operanac wita plus opercdar.

ReplicodionOperaor

Theoperctorwen used u no pertorsmuhiplicahanit

when bcth operadescre^ skinaand^ ha^ and^ returnsthepredudct

n (^) operands Whle sin thereplicadion_operatortheoperotiodCon^ beether no Stringststriag na^ |hestriinajeratnrtellshesdriag to be^ replicad.edOndnoOerandfells_no.ob dmes^ ikist^ lhe repkcaed 2x3 (^33) Me (^) 9:MeMeMe Me (^) 3':Erroz

lassMate Date Page

aloc A Tre

AGc"ala^ rue alac2ala2IrueA

Deternaiain4theUNICODE^ atachafacterhapres.entinga chacacterla UNICODE^ value Plaon_olhersslauiH-inunchian^ ors^ and^ chr)uwhica.areused |displauhecorsespandingoraliaa^ UNICODE^ valueot^ a^ siude Clhoa.cierpossed^ andossingAlCODE yaluecoreinho

OrIeSpandliaacharcderreapeciuek

print(orsCK')_ 15 iordC) 122 primhr(7) pridcar(iao))

StringSlicing The meaniiagok alorosliceoneansaparto laPahaa stingslice reecsp aparto the stringLahere striagsaresliceduusing_au naeo^ indices SttiungTmlak4a 676 3- priatLstheinglo: 912 Taalktaiol printCstrinqA)5T

alasSMAte Date. Page

pri(stlng3:6)bak pini(strinaLa:) baktaa prinCshing-o-51 Tiah prin(stinLo:o:2]) ad o prinsthinl-9:0:31) (^) Taht printstingLt-2 ookglamiT s

wwwwb

strinatuncionsand Metaosls

M Pthornoßso^ ohers naciaym-louiltdunctiouscndmethods

ADrstrinnq manoulathicatver sinaolajecdhataiaercreedes- Patnan isacuhuabl on instanced string,class.lhesdringcniaulbdis metnods are oppliedostoingOs per thedollainsatax ASdriugcaieci^ me acel

Ihestcin4 mcnipuletanaethodsinPHaon ose ring contolize() reins o^ sdsing^ with^ dirstcharmctertapidalized Eanh love^ mu Incliolnclic prini(s.copitali2eu) loue u ndic

dnSdringindub,Tslai).Lendl) returns he lowesihadexindae stsiugwhee thesudastingis dound withiudhe^ cliceranseot^ shardcnd^ eud, ta S2tgoesos-ringaringasses prinSindl"ri) 13

pridsbiadlringa15,22)

elassMAte DatePage.

tg piaSisdiatc)false prinCissiaihcFalse pciatS isdido) Tre pi (^) (sa icdigdO) (^) >Fals

iielowerO: renns_Iruetollcased elaaroctersinthestingore lowercase, There wus lbealeasonecasedchatader thecisedrehurnstolse S alac S ALc S Aman?

print(s,ielower)rue

prii(sisloweiO)False

print(SgislaweC)2folke

prinilsAislowerc)tase

tinaSper Aests_sheth.er alHhairases_hatadersinthestingareuppercase and (^) reuireshadtherebe dlenshone (^) Cosed ch.ataderlsa rehurns Aue cdherwise fadse

Eprint(sisopperO)LAse

prin(s ispperc^ rue pri(sgisuoperC)^ felke pcint(s4 icupperC))^ False

oii tringisspoce retucns dtrueitthereareovlyMdhiorlblonkSpacesnharaders

elasSMAte Page.^ Date

hnhe shting^ Theve^ mus^ leatleashcrecaataelerinestsia ctheriserelutnsalse inh(s.aspace^12 Ealce prilCsisspae0 Ealse priniCsisspaceO)^ False prin(saSSpace()^ 2True

Shl owerC retutnscopo striuqconverdeslto laiercase t prid(s.lower)^ ac ars auer) lac prindCsslawert))-2man SOo band pritsalawerC) O7aand iinapperC) rehurns (^) Copu othestrin converdeo (^) t uppercase

priaCs L2ppetO AMAn prindCs4 upperCO) o07 30

stinaashpO rehurns (^) tHecepeltheshigtHa leadiycharaeterscemo (^) ved isUAR (^) wdhoulany (^) arquieatremavesHhe (^) leadinqshite paces Eg s^ "Helle printC.1steipc)-2Hella pind(sstipCHd)-^16

elasSMAte Page^ Date

priaCTsta)ae^ aligds^ are'de) ptindTlalalphchetsore^ al)

QNdea^ Python^ codehiehinputsa^ stringond^ chechwhether s palindromeo^ not iapupu^ Eder^ ainq lanle) otin o pridse(Anph^ Enteraey^ leter^ R Aat iinrangeCA^ )E PprimS^ HedlinputlEnherany^ letterkind)).

pLi isApcliytame)ssdndcla

prinik1<a paliudreme cEinputlEmet astring d prinCc:-1) printLcisapolinl.fone)

2slal