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

Functions Notes

j

Uploaded by

mukilsanjey12
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)
19 views12 pages

Functions Notes

j

Uploaded by

mukilsanjey12
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
fee FUNCTIONS’ Funchons ts a Glock code which runs an when i ts called. ailise Reyword ‘def” to defiie or declaw function. sunt (4,0): f pron (at6) Sun(2,3) wo LG flae Sum is bey collet & ctecute prick statement: ee types of funnhare, ee pytion finctions: dotr>. split, appadO cke.. © Guilt: ie modules: traport. vaiedonn, prt slatistis, pike 6 User-defireat funclions: The fnchions which are not builtin but defined. by users. eel C) = prot Hello Word) gyeehO) + tlello World Gna) | 4 lit wanna. get ith a SLT’ name) | e'Kvogpat) The above ode portrays fow Furchons | cllgeC Kanye?) eay Ge use 6 rede a. ake colltge (pelt) ~ © scanned with OKEN Scanner |ctuctwe of @ User-defined junctions. é > (parameters) julio bole i > Cp ft A < fonction Gody > Cretan pert ne cfnc-nae> CRogpoens?) | 2 pada fore: The above fnchion. works only when. furchion ts alle. ba fhe named variable folds variable [accepts values. (formal penal ( (formal a a - follows rules of ident Arguments: Tie oe wis whee gives ceput to inte B ryote): _—-‘Aeval porareters) a mem rate) feluol argument wae i Payal Iopanas ve fe be declared proper postin in uy ya rie ined ) prod (sums, 12,50) © scanned with OKEN Scanner uments Soramelers: a poramelers ie which the values ars asincd 1 parele whe dedarng fincin-hender sume (a,b: c2 5)* prott(asbtc] sum (2.3) #0 Swne(2, 3:4) #49 G u will ovewnite sum(a,b=5) C=6): pratt (a+b +c) sumec2) #0 gune(i3) ll Nove: Default par amettis necot not Ge declareol in fonchion call. § Tele it will Ge overwritten. sum(ars, G1, CF 23): prick Carbec) sum) #4 def sum (ass, 6.0)! prick Casbec) 4 ror because °C’ tS rot feared. gw(2.3) Cit doesn't follows rules) iN © scanned with OKEN Scanner § sync (213 92 + Error. beause tb doesn't plows ee declaration A default porayieter’ shoul not Ge declareol be A defa cee efte Yon- por > Hore, a U3, declared before G which non-default. def gun( a, b=, c-6) df sum(a=5, 625.0810, LIA def sum (a5, 6, C2 to, d) X word rowentts: t value qiven b a parancler ie fonchion. coll fe def abot ( sd chulent 2, studort 3) : print (Mey ‘favourite ctudent is’, student?) ethonk (‘Ner’, Bob’, ‘Chales') HMy farorite student is Bob. School ( student2 = ‘Bob’, student! = # Ny favorite dent 14 £06 / Sore: Soy nee order doesrtt matter f every pooanelor fos ipt fult value. | def svmCay6c): print arbre) Sum Ls3,c25) 410 cum 23,025) # eror(a has two values) : sun( 2.6235) 4 enor (Beyword argument declorek allegra flex’, student 3=' Gales’) 4 © scanned with OKEN Scanner f Values Cusing rebum shaternent) , Retun: This will store te result of the igalican will retrieve output when furchion Us > Tes ts nd of execution. fu: 2 (2,6): 1 def S sunt Caio): 4 shart Garb) prt (ato) prok(sumce 5° |-pri- sumct3) HS as sum(G 5) i ar aus) Hil prckle) atu pride) Hflone @ Reburuing Somelfung lon voidl) @ Nor Rebuy Wid) def Suy (ab): | sum (2 pone —+ Nlon- void te Statement bef sum(a,b): sum(23) thi. © scanned with OKEN Scanner an of eee AO APRIET eA pees | 9 def aun (a) gearb b return § Fai lt oy tame Dz wt vital a wanber: 2 a dike wit er rummber: ")) Hite outtsiole of a. 3 = snl Ma? bd (The sum of two quombers ts: ”., add, function) ttlawelor vst ity Fae ae Scope of variables: How & gariable can be accessed insidel otterde a fuuction. The. variable whith 1s dedased inside the fiction foal ee fas al sope 12 oleh 08 (cal variable. f table cout be aceened odside the function oa snp» les which ave declared outside te Gide pe» i yn et call as Gobel arabe of global yortable. an be acces, aiynlon i 0 praia ( nse ota the Fo In). » focal var © scanned with OKEN Scanner ” def divisor O a5 Ls (ual voreables 6-6 (arb) — carte accessed tnaide a. fine tine at G1 hal variables : pre division C) pro(od) 9 yea : 1 15 \ def sum): ( (obal, azlo | prixtto) sun) = Flo print) #10 SH mokes ‘a’ a global ase © scanned with OKEN Scanner a B) chack HL WOK, locolal er» WE ned bo-veverse He (2S gut tum. Aahwe YevNumber (um: YWE0 MNO, Whi Wn? 0: tem =F HOMY 10 TENE YeV® wo yyern hum = Num {Ito - AUN Ye aint (sever (42343) BL dah erWunteer (nod + i Xe YM =0 joohit NUM IO; i em enum 10 : IN = YeV* Wot 40m j hun = purnl| VO CHIN orev pit (yeaNoonber(1254)) © scanned with OKEN Scanner @) vsti a fue poystnow CPLACES) im pylon, drat dake QM) yu dlickionary PLACES Os On argument andl cliplays dhe womls(in ppor cane) of tre plows whore pare acre Ameer hon Scharachers « For exomnple, gomaiber th Aaloving dichsay own {ys “puted” aod, afar, 4s SNewpatk 6: ae} ". 2S Leb» GauundkNows (PLACES): thre % Jon Crurnces) 7S: peers DOT = PLACES “URED Wegk » rink (ovT) : "9 “git he counk ® by tan saat) deh Counknew (PLi/ PLACES) # Ape tin PLACES": if aes CD22, print (1) ug per 0) 8) writt fu’ Ln Words (string) , Yhoks doko ashing ad an argumot frdurnd & buble coming Ung uf gouh wvorch of ashi Fos entry, Hf Yh shing ® Wopme We uD have Pars fo Ye Aug will have (4,3, 2)4)4,) © scanned with OKEN Scanner fs dah, (woWotds (STRING) : % for Lin (STRING) OC = Muple (split STRING) pont ( oe 4 4 tonwords (eraiigy: et. Age ihe STRING, split) ; ] : fc tiny have We donk wnt te wut t=() divecty in lin a - emia ‘. } tious tiple doo PIINKCA), Faive oppendl fortes fugle In jrnrudable pe dh fortWorda (STRING) * ces t-C) o. Le STRING « split) Aes tml: t= tt (nc, print (+) © scanned with OKEN Scanner 8) ait aft TNDER—UST(ED, whure L is de lat coment porsd an onqurant of he fin’, ‘thy fur’ rebures anolter tat rains Sinden lat” frac shoves dhe jadivts of ok rn-70r0. elven fer tinrmple: if L contd (12,4)0,11,0,56 The indorbit will have - [oy1, 35] e | a dh WOES UST (L): d ‘edeabak= C) » frome nes | wp » fbeor wget te “appeal paint > » u wy ‘INDEX-LIST + 4 indian f= {J ri dint: Ife = =O? indtalisk « dqqudkL-indax(id) print Cindsalist) © scanned with OKEN Scanner ye ~ dah, INDEX LIT): nd ist fork in voroe (laf) | WLLL: BON anaes ndexfist) 8) Wedik Ye ovkpuk: Ves dh gum(A=2) : qotall ° eee prin (R, end=“) a= {0 b-5 Sum (080) Olp= [054 6H Sun (15,421) et © scanned with OKEN Scanner

You might also like