0% found this document useful (0 votes)
62 views12 pages

Python 2022

Shim

Uploaded by

Michael godson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
62 views12 pages

Python 2022

Shim

Uploaded by

Michael godson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 12
Bs And. Tre not hh operator t o¢ OING. SS Rca Beats on ender scores * * Spaces ane not allowed * Pymon Wl mot accept ©. $x % + Ryton % case censkifve, © ‘Helle’ ond *A class name ull always Store wu o WRat b& te Perpose O8 noe th epetotne used to cReck as Pdentietens: pelle? once Heese argerently copttal letter ‘ tn Pytion- sting of Set- mm a Sest, Septe, ecegted element * ating wheter Re =P og evold) Ranckfor Im FF present value fndfe wat & Ke ose yhoo % The evtO He expuesion eyntex® ever Ceneres Lunctfon vaduater Ke spectgred excenesstor » 2 ae legak pation statement 9, alobals, locals) Peer ertias belwere PUES aa ed tp Pee Pn Pytom- ovtded by Re Te mourn fancier gnterprets Re enput &% Rae an Integ@ vadue of Empuk, Ren 1@ usen euor? get value - user. as Gr wl vetusen On Enter the Impue Geom Re tre @mputd The vous Pmpuics Gunctton also takes does noe Imtenpret de Imput and also use wiout any change. break and continue user but et fe etns Ke Mmout o& te WwRat Be Ke AkeGexence between statements fn PytRon> | Shep Re loop even Stops Re executfon Confinue Statement f used to Stop Re and comiPrue wR Re Nene Penation. de vet post © Be beginning o% te whfle Loop. 6. How can you Create an Imgrnite loop: 238 ANOS create on Mnglnhle loop, you com ote & whSte toe ate | a condffon Rot B okmays true: 7 Gyr whe True: prine C'inginte Looe!) ee te lambda ernst RB a speckal type yword lambda B used fo deQine fees). A lornddo. gunetfom o& Gunctn witheut Be Gunctlom nome. Ke, Rese Qunciioms. Syntex t lambda ogee Eg greet = lambda * print C“ Hello wert”) nec % escpresston - eee ane Lauer coguments Be Pytion AND. Am keywouds arguments, Re colle recognizer Re rts Gupe oF eeparénks: by He, panometexs Heme” angument: tan be skipped. gt >>> def sumOxc. ed)? weturn 2044 >>> Steue print Csum (= 3.453) 8 dole. q. DeRerenttote bebveen buflttr Guncsfong Ard “ser AeGomek Quncfome Pn Python Aye). Bulle fm Banctfoas Ot whe Gunctfons olxeady deGined Pr Ge Python pruoquarming Language We com BPnectty coll et Rem to perfoum spect&c tasks . Pymon allows vse Aeeme Wee ron Gunce®oms and “Bese Ganctions OME brown as user-degned Qunciions. The . at der & used © dere a user defined Kineeten, a dn SS (an unoudened collectBom o& Unhame | be created using curly braces 9%, Sets one : aa Pke removing duplicates Grom a ME Peg oH moatRematical set opesattons + i Hous asttl you reverse a Ost Pr Pyeon? AnD, Tre veveouecs mettod & used nevemse Ege po my tte = [0213,%. 5 my —(t-veverseO print Cry -\%0) ' [e4.3.2-01 aelr Python dictfonasts % ondesed collection of Cemt wRA o keg. a Mt fr pymen: f2. Rat do you mean by Ang) The Pyifion dictionony Ps on vn On elements Im wRER each volue & agsocfate t The elements Mm a dictionamy we seponated by Comins and fs enclosed wIRIm curly braces The Key and value Oe geparated by a colon Eg, rr dietl = Zi “ved, at 'yellow', ar'green’ § 13. WKat one destructong Pr Python? hot ges _-del-— ecPad meted named ed. Se & Vted Ans) A destructon B® a Se ck & about © be destroy called wRen on obje Gr cleanPmg op Merounces of pertouming oex cleaneP operatfons begore object Bs deleted From memory. Ble Mm Pyont 2 os module 1. Hou wl You vename — |dnd) TS sename a Ge On Python, Ea: fmpert OF old_nome = ‘old— new-name = ‘new Ple EXE you can us Pele ext” os.rename Cold_name, new-nemd) 15, What % te use o& .fmgore statement Pm Pymon? he pore statement & used to bing external proguam Jt allo, 5 = precedence Br precedence defen the orders On lous, ane evaluated Pn expuesstons. © - Precedence B eveduated oust. At of puree Dr Rerencthesk€) Bch Exponentfad opevoto” ects a turetelfeation “+ easy teton , 1 ei Adateton +. Subtraction civ Bttaobe leGe SHEE <<» Brute vat BREGE >> Wy Bekatte AND operator & WE Bluse KOR, Beuswse OR \ aly) Compantsen operators <> + <5 Wild Equality, comporton operators dy Asstgmment speratort oe ene odutus Jo» Floor Avisfor a ea 00 (dent®Ey operators ? oh) MembexeRip operators! fm, noe tr go bogies? opersert NoT,cR, AND- osePimetic OF gm Py on - coors 1a. Give an account OF ex Seamer opera! Pag). The ar eerert 900 oem. ters Pn PytRon ase 4, 5 f operator Descatptfor 3 I Exarepleae + Addfiion operator fo add Q operands totam eae = Subtraction operator {> Subtract Q operands |20—10 = |O | (0 #20 = 260 B/2 295 ak Mulifelfcation operator to multtely A operands J Dion operator fo Bite 2 operands | +* |Exgonentfad operator to calutate power % | Modulus operate Lo Meio Foo ANBfin operatou to Gind Me quotient and Hemove the Gractional part - fa: te x >ot prin (“ Postisve™) else statement? ; , of te cyotunted Py We. Onna & cuee he fF body Omerutee else body & executed + Syntent % condition & statement€s) stotement(s) gi Te x B2==0! prime ("Even") elec 3 5 prime Coad") GD ee. clPe ctertements? Tre cl ctadement allows fo erewnelit heck multiole expressio Gor Gue and executes a block o& code “os Soon 98 one & Gue, Syntax’ PF coneditfoat & Stmks. ARE conditfon2 * Stmts else ¢ =To? print ‘A’ exte score >= 803 print 8? elise t print “c? 1a. Wskle a proquam 46 Gend “He ANS) der compate—lem C4) else * print ("Postfve and od’) eke t prime C°Negattie") ne Lem of ang Gee PeGe lice, = i4: t greater = else = greater = 4 woRRe Tre . TeC(greater % === 2) and (greater y lem = greater break, Grecter +@=\ return tom Tne (Prput ("Enter GE number 3 hum 2 = Pot Comput (“Enter second mashes Dy esult = compete—lem Cnuml,nen 2) PrP ("The Lem 0g”, numl, “and” Amma," +”. Tesute) OvuTeuT? Creer Gest member & Enter gecond number 210+ Tre Lem of & and lo t%: AS gt pop count =O at. Aw. > while count <5 2 prime count Count + = 1 ouTeoT: seen ea ei: 2 oe an op tfomad dam maken es we Yoop Mr PHMom ewhen Re comadPeton of whicR FS executed else Statement We Qoop Farle Syntax + >>> weFle condeefont SEakement{6) opp elee t Statements) pecount =e 2 wREe coune> else % prime (“ InsPde else”) outeot t Gime Rmstde While 2 Hime imsfde whfle Imstde else - Pe ne gare Ot cynter o& any Give Sting Rermetiing enctdms Fre Pyefion cD coptialere®) 7 Makes Ke Gt Detter of Re sting coptent syntax > papteatteer( egy shing . coptéattze W long): SH vets He Leng of se shhng Syntow 7 len (string?) a2. AND de fealpRal 2 IE te o6fng Rag atleast Ome cae Ranacteng ane alphabetie, fe vetuuns Tue + i OfRenutse Falce Syntax —> String, Ksalphiad) ew BARES > 1E stiimg contaims only numbers hen fe (eee We. Otmenwte False - Syntace —> Wstving. BARLO ety Cowerg 2 E converts afl uprercace letteus to Cowencose Pr a StrPmg, Syntax —> StPmg, lower d)- Explein Ae various wnodes fou open@ag & le Br Python . vt Bele can be opened O88 Fele_ object = Open C fele_name access mode) Diggerent modes o& opening GEle ane t ) vy —S opens a Géle Pn vend mode onl % placed ot Re ctancttng of gle. le By fe defautt « ty The Gite potter > lt opens Re GeLE Bn unde mode onty.lg a Bile exh, PE ovexwutes the exfttiing Ele, Otieusie & creates a meee Gite - GI a —> tt peng o Gite Gow agpencting. The placed at end og @Ple. Ig te Ge Poer nok entce, Pt Create, @ new ile Gow wHreing canctee. ony nck append bw Qe potmten Le irBisbrab pope Gta Fr reat ortss mode sespectOvedy fn binony Boumet WW vt, wt Pope Ble Gr both reading and uniting ie at — Pit opens ele Gore veoding and appending ab+, w+ —>l opens Ele Gr bok veadthg % witting th re Fir a b+ —Plk opens Ge Gr Yeading & appending wh = for abe what axe Re ape ; QE OG Ob; 2 a beck Ortented Prox gyammeng 2, Explat % Explagn] Object -orPentect b Modulos oe ny Ca advantages % a : 2 a : eet! OOP pucmotes te organization of codes Inte m odutan stvuctwmes Kmowm os clastes TR | enRances code cccusabPlity anct mamntainabllity , | 2 as cCRangeg tp one pot of the code dom’t | necessos®ly aggect ote pots » | RevPour won | UB Encapsudation § ODP encapsuleter date and be Qntesnal decals .| ebfects sprevenEng Amreck access 4 ree een ee es complexity by Rrding Gmnplementeteo™ gocus on essentfal cennecetsasy, AeeDas THES del and makes tH ps mancae hotell - | Abstraction allows develops Geatres whtle Raqnordng, Rerptehes the programming, 0 fe conceptuckze Land desta compen systems.| Wh Posvraction® eostese by MRertiing attrPoutes exc t2rg, Diet ee nce OE code Meuse, a nelatidruRtp between clos! eakabees gadtttate creation 8 RBoancRPal stractures Ly Rodger Phloem % Padyrne: 45 be treated Thee Qestens Gtexile2ey He codemaking tt casten > adapt to Ranging equinements « sex ond pphitsm allows objects o& Arggenent Pylon Boo MEHTA Level grreval purpose | Lomguege es PI he code wrPiten Em Pytmom fo ontomaticalty comptere | fo byte code and executed > Pyrom con be Used as a scedpting language - Sfuen con be extended WHA Con Crt 7 PyRon Supports many Geatunes such as ested code blocks) Runciama, Clasees,modides & packoges * a PyRon mmmaker use 06 OOP approach CB Mere ane 3 dierent ways o¢ stauting putien® u a - 4 eared a sx2pt wattter En Python “Using a Gut fuom an LOE 3. Exmploying an Sntenracttve approach. =The eo a ees O Ese appro ae wing Re * We wll Rave f create out Seem fene editor: 3 a en ee yr *Using Re Second appnoaeR one Rak comes 2 Pmstoll btcetg- Drtede on on corinated ° Using Re’ taiud agpronc® ‘Ke puthom P Ceme Enlerparctar Rat wll use eapproack- op. Discuss Re ARRrenk arqument essing mmecRank em Pyom wih Suftable example Ars).dy Requined osguments > When we agsfan at Be ime G Gunction deQinzefon , fe oxnguments sould be passed & a Ganctiom fosifomal onder» Ege >>> def prfritfmreCetd print ety Yeturn 5 2 oe Be pouametens 2 O Kun ction ak Re time of collPag , Bm commect 5 Keyword AareAdnguments § Per er enents ee cotiene mecransece Be asguments by Re parameters names. Gar >>> dee prlnt_Ofmes (sts) prent str rreduen o> printline Coty =" Hello") Hello 4tofp. Gd Degaute Arguments’ Im Rese anguments, we con Value f a parameten at Re time o& gi >>> der addfifon Cxs4 = 3) Yeturm 244 >>> print (addPitin Cs = 5)) 8 ofp. WO Vexfable—Lengin Anguments 3 i Gn cates whence WE TOBAVE We use iese aqgumentt in. enti mone numbers atsPgn & degeuet Qunctiin definition. ane neqned 19 gocess o Genel Be arrest naed cretgied, f= GS LeQeneerdn + qi >> dee printf Coxgl, ever eipls) premt CResue &”, e731) Bx var Pa vartuple prfat vor return Soy petint ta fo Cao, 6&0) & to Pest Ee ae pectongle a & petmetes 2 quam © Gand oes Bh. Welte a PO Ustng close K obfect- Ag). class Rectangle * det gate _Ceethvtenge eed)? i Selg. teng i = (eng 40 uke = RAR deat a fextmetert 26 col — pextmetet Csetf)? 2 (erg lenge + Sel" steliso) Teta col 27eA( E18) F vetum selfs Lengen * sett oPheR det inyntectangle = Rectongle C528) cate_area()) pant ( “Areai”, toy-tectemale- cat_perimeter()) print ( “Per?meter:” my —reetongles —=— 2A. Wwe a ans ok axe mutable & Pnmutoble objects fm python? Explain eae dot, te dee fry deck dite cotagony and fe cucctated methade wR examples. Arie) 9. eey Mutable obfeck axe Ha obfert ot con be changed ohtet one cxkoted. Eqs Lick, hc fonary re trey coe created Hors # | | | Immutable obfects, cannot be ¢ Egt stfng, tuple. Mu io Durable Obfeste : . Bip senusenecy, Gs >> my_lfeL. append COD + my 1 oop prime ("arse i e (.2,304,5103 sO/P- Lie teers Te iigenlie te Se BH Deceromasuy * Dictfomorey WRIA ereny Eqs >>> my-aet = 1 25> ey diet [QJ = “TWO” my eet) Gemeks Meet >>> promt (“DReuioneny © Ofcefonany P% FL Lt‘one’ 5 lmmutable Objects? Bixfing, Tomer: Semmence eqs mvt = “hello python” sop Vor[o = ‘p? Error eelee cal oR area ences comma %& enclosed PRP C) Eq* a> be = Cite 25p) >? &p(2} ='19? Gro sHolP+ og Prditdned Ramactece dy Serong + vedues 2 Tepte bos - ~ le He Separated by

You might also like