0% found this document useful (0 votes)
2 views30 pages

Python unit - 02 notes

The document discusses user-defined functions in Python, including their parameters and return values. It covers various types of functions, such as those with and without parameters, and explains the concept of variable scope. Additionally, it provides examples of operations on lists and dictionaries, as well as the use of built-in functions.

Uploaded by

Pushkraj Pol
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)
2 views30 pages

Python unit - 02 notes

The document discusses user-defined functions in Python, including their parameters and return values. It covers various types of functions, such as those with and without parameters, and explains the concept of variable scope. Additionally, it provides examples of operations on lists and dictionaries, as well as the use of built-in functions.

Uploaded by

Pushkraj Pol
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
set { brary ae D <—fpnction. Lt 8 unelfon [Ltt pnditn lithe buttt_tn Spunction ane abo Called as prede inect tunctfon means —there ce “the fynctin_which are qhea Present to paodamnctag. Ubrany “then (an be vse Ft linect ly $4 Enpot ©. pital 1S9nO, powo ete : | F - { User Gleffinec_ function Bie Is The fonctions which ore, Chekinedt by the PwpIamMey gre. < User to “Saws G_ Speci _ Operation “On the tasls ar calle ex Ceffoc — ‘Syplar su ction name Cparametty-list) 2 fortements J Hanes eg, tse Keyword Us used to crate ‘ton “fn 0 python fynction- ees name Sten toc fyndion porametty- liste The valve, which ae _p gly jicet Slakments i The Set of tasteuclion to ber perp preter tec ; L afes 4 + eg add (ob) + zatb qatun C Calling User defined sean cones er, Pacace rend pe czatb patel CR tela itioo laag C05) ae [bssGs.s5) aks ond de sr6ements FRaométers on nthe variable listed inside “The paraithat when @ “fynctton 8 ctetined __ ‘¥ 1 Function with parame and aetusn Valve add (ob): __ c20+tb ta 2h gelurn C =HniCinpat Center rwmber 2 \o")) b = 2 tt tnput C “ents numbers \n")) Cf Addition of, 0% and $63 =Saad(o.b)3\n) r a a(a.b)t CTs" wr -atb Cal Sse: - aeeoh ET ee print Addition ay and $b% $C, B50) “tntC tpt CGrtey_rymber 4 \n") ; = tint CEnputC“easter_nvnber D\n”)) Toda (2.6) Function weth aewIN Valve and To porametr i add 02 = tol CEnpol Center rwmberaio")) b= int input” ‘entty number? atin ab - Czadd0 tot Gy Aadtition of 26 ana 365 H Function with no ‘povomet> and no velum valve. Bef add: a 1G. = sot Ctnpsl Center ambaalh iu b> tot Cinpat C"¢ ent bev o\n")) _paint yy £ “Aaatttfon of a} Gl na eS: add c). SE Aefanlt crrdtrment S 0 prangter i ce Sefault Vowe- [4 no vate iS clorinf, “the sfyrctton Co pgthon wseubrthe “degput “valve. i on _ sli or mort Gefoult abr e Default valve, ave Used _bnly when no _COTres) rBuMment tS provicleat. 1 [Scope of, variable , Ty pe tet, “that “The acces; antlity cn a variable in a prodram . The Scope Can be “Gasidad to tun “types, Local scope [vortable Global Scope | vartable : I 32] Globat Spe [variable {lothen G_ Navigable @S clettne or oleclaxc Outs@e —the [onc too Gnet “thet Can be accessable or Use anywhere] [en sth pmgram when its Caller global Scope. patst Gy” fidetitfon. sae Kemp ( Ani” vatwe of ne =F bein) __[prtnt(y" vate Of @= Saf In" a fon wilt Stop Cage » - - Sten ents am Use “Lo reauce “the Size Off problem anol wach Lo the baye Cane. = Em cvrsten fynction “lo nd. fpctdrtal cS @ Biven _ nusmbe def, fouct (09 # @ i (nee os - “redtunn 2 apetorn nt foe Cnt Ly nzint(tnpot (~ Enter “@& _rwmber \n’)) Ls olga =46 nini CS 4ectortad_of, § n’Sjacicm jn") Ges .Be to 023 pity G Umber focal of sxfoci(sy=c aiees ) 22 n(sd4 fie) prfat 460) = satel Gyre 5) aaa range (0. 1-23) Da peo i prtnd CHOC) = fIBCO = © 14a) ag pib()) = 4x00) = + Lolo -D apie) fib CD \ Ahh OD 4fPCD) = 4 wut 24’ Snes the valve of 2 4 +Ftbonacct numbers ore Qed. 2. Rewrston function to {no GCD ao ston ae fe ms ioe Nz=07 OE nm 5 365 A Nem Yn) tact aed et ci aia jactovial v4, $n3- FfactS\n Ds int tnpat ("ents non nepeiltve sumber \n" “Haclortat Cn) stra = “Htello™ gies ar sind astra printrss vt) ‘Output Hello Python fing Slick gu Slick is substyacl _esecot! Ne ay Sot B didit $4 Let =" Prosyammtnd’ Ent Ctext (0x9) teat (5 32) Creat LJ) eas (iets i es ‘ { Sian &tring_nom[ Start astop $ Step } Sra et Pte ee title © te Converts! tra +0 upper tn 9 | eaptte: s igs oot 42] Capitalize Conveyts the pels Lette “The 53] Stotpey TA removes, Leading anat tye G laceC> | A oeplaces) a Substring 7 3 | Y yl Pred c | Tt retire the tnolest of 12 | occurs 1 a 2 {Count | Goons “thy ecw ran S, SUbStD p ~ chanactes > pistons with Checks, ite Si7te ston & Qubstring | Jelena with) | Ghecks 5 te string _en a vb WC Splits a _stvag _frto ep teil ist icine eb, ean, teats capttalize ©) tot cater Strips stent. Strip ©) gic” orfter replace’ “teat mplaceC Programming", | print 4 Hind 2°) “teal effnd.C” pro” aD) fat count of 'm's steat- Count em) iprerit C Starts “with py s”, text- - stovtsutin® py) PC ends with ext « enctsw ith CD peta split +" text. split ©) Le [cess “D") TALC jot + text. jofn CL) ae muloud Olailartypes ~ [eegu LL 20-0, 48) Sfp te eu L= [1.20.30 ,40 fx ts(s 0. 40) Les (10, Tre, “fc”, 25 [Operations on List (holed 3 Et &S vped “to access and seivisval “Thdex _opercélfon 00 lst T's Aype. ~dement of Jjotunouy -witvm, “the value tothe spr ol, Sel Usb. behunns the _ootput ain oy ey Mh te Sei iaite [ts.20p50 4D) tro prtot_ Cif) _paint CLEa+3), point LL AD) a wore ec = aa Me tena [30-42 = —. i nt (et te : ——— Billis! - re O/p 34 10,20, 30.40 Botlt th mathe, Of Uist : i Function Name Degfnaatfon Fool Append © “aas,_an element at “the end. | tysert © Anges _ on_ element alo Speci 32] eatendo tals _pottiple element ; r —— — —_— cpempve ©) Reraoves “the Spe fe ~ sahorient 4 St|__pop 0 Removes, element esting, “fnolex 1 eae sort) Removes itl _ element Returns “the_pos tion rar Cougts Ocuvans of an 4 4 j Sovts the List fy axtenolins 0 a e ane t iy t seuewsel “tu ghey. Rd J & at Gon tage ra List & A nesira List W @ bist The Westea List sa one or mor List TS _usetul $07 pepresertind Dimensional Dala_ Svch_@ [matrices taple etc 20yu L> [10 2080-40) » | $ sol CULD) 4 PreguCUGals (out 5 6 OF 3 Spotl (UIC) gutpul 3490 te ci +f 30,40 * y 30 2 @ey b> [roto (3-40) 55], G07) Oulpe te 160 print CLOT) f = | prio CLEILILA) (Dictona 1A diconory (8 a built fo Dutorype Bed a Stor cldla fn the yorm of Fey vou So Key D_ vrigve anol i> osed acces PES Covresbencting veelve » 7 clictionary enclosed | rs where each hey siporates rom StS vole gt | pirrese ere _ rmvlable data “AWypes. Eagusub-(c’)" pial (Sub Ci AD Goncatenatfon T+ Combines -two ov move tuple Used “+ Operator gas t1=C 20) ty=(30,40) pant Gta) [Butt ty methods * Ron ; 53 to st tall een eto vty gum —_? ot: =the “tuple r= (0 , 20, S040, oe i C vripinal “Tople +” int” Length of ple: 5 tu) print (> occurance 5 20 ta -teple > 5 t-count 20D) fat tncex of 20 f0 Avpl =) m9 fndlex (20) iC mfninom of, tuple =") mind) fot Co maxtnwm 0 tuple=", rare) pumerte eleme unction ihe potnl(” Sem 0}, “tuple eloment = ‘Som CY) Dip eu tiple (iv.20,30, 20,40, 50, Go) a = S Ee ag & a a 4 3 & - i 2 Sa 5: 23.5.8 VE LeePn5 A operction®, “A ANB & [Link] frit BUStNE Symmetaic Atpterncecd 5. Suyrum cate. Ovtpul eu Use \ operator $2,9,4,2) bsfno See ee Ahernce 31.2 .4.8 ‘Bott fr tuncttons of, sels a | Function name : Baa fon IP addc) : _ Ado. _cthe elements” 85t0 ia: i Update ¢) Adios ru ltfple element fnto set. wemovecd 2 Tl remove, an element soem Set uncL raiscard O Tt emoves an element don &

You might also like