0% found this document useful (0 votes)
49 views

Python Complete Notes - pdf-11

python methods

Uploaded by

anupamakarupiah
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)
49 views

Python Complete Notes - pdf-11

python methods

Uploaded by

anupamakarupiah
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/ 4
Example - def fun: Fe amps eae Weltome to GF") a He Duiver tode_to_call_a funcHon fun ofP ~ Welcome to GG. ’ i Befining and calling a__funeHon «with porameters a - Syntax - de? Punctfon- name (_parametw : data. hype) Heturn— type : ' _¢ WP potting _ # bed of the function * Heturn expres. en Example - some more functfons def ts. pute Un): ‘pein [#3]; “uehurn Tuue it (mé=1) or (n Jo a==0); Aehurn False wed while wey ern: Af ne wes 0% ritkurn False Hee? xthum True pata Cis. paime (78) , O}P - False True = ~ a Py Date -..-sescseee 2 Anquments of 0 Python Funetfon.- t eo Auquments are the values passed — inside the ~~ pquanthests of the functfon. A function canbe have an number _of, arguments sepaated by a g hJT comma. Example- # A simple Python Function to check my ee aor” whether % is even or odd re def evenOdd(%): Sy __pattnk ("even") ~~ else? ’ paint (“od d") ~ # Daiver code fo call the _functfon oy even Odd (2) evenddd (3) ofp - even = odd se _ ye Types of fagamneals = = <7) Default arqument - It fs a paramete that assume moat default value ipo value. ts not povided a | agi: the function call for that. argument, i [ z Example - def say Fun (ly =S0)+ = patat (“ass k) 2 "pata (us, a) a # bulver_ Ode YY we call muy tun) with | i # only aqum ent) baie my Fun (ie) : o/P- %=10 i Be i toy se) 4 _ Saeeat “J De ead ep ot te ee ge ne ae ee ge < | ae = Tt | keyword augumente = | -O_teywerd = allow the caller fo gy the argument name swith values = Hhak | does en need fo stemember _ the = Poxameters, ce | a : Stud Chttsiname. lastname) —Lxample ea a pint (firstname , Jastname) iy # ksqword_exguments if studenW( firstname = Geeks") lastname =) Student (lastname s'for', firstname = ‘qeeks') % {ih Se i oP - Geeks for = i Geeks for - S -@__Nastable- length arquments - Gi we can pass a vaufable number of argum- ~ents fe a funchon ustog specfal__ symbol. Were @ axe two speefal symbols-J | 7 & oe args (~ Non-keyword Ar uments) “fy 1 **kwargs ( Keytbord av flonsnts) | g g ie Example: - def my Fua (* argv): Se fos arg: tn’ arqys "pant (arg a my fun (“Hello', Weltome’, “re, Geeks fon & Geeks tee. O}P- i Hello ‘ Welcome to GeeksPor Geeks Dosstring = Me firsts ¢ the Document _ used to desertb the ee ae ° ° ~y short. Inis ts iS b eof he huncHon. Ine __use of docstring to pn a optional buts thts: ston stdiwed) a good prac: For Hees ~ Sun fox = paint ( function-mame.. doc-) Ss Te : x Example - de ebevenodd @ 3 ‘Funchon te cheek whether % fs even ov odd + St (eo 2 gaz}: ~ paint Cever!) Sy elses ag uint Clodd”) = we Dutven code fo seall the function =) paint { evenOdd,— doe —) * “és dlp — Functfon fo check.if Hhe number fs even or = odd. Re Relurn shatement in Python function ~ the functfon sNlumn “statement ts ured fo ext hom oo function and _qo__back to the funch’on caller Ta tand aeluin the _specffJ i value. or data them fo the caller. { Syntax -_vaekurn [exporession. fst] ay y The seturn statement can consist of a Variable, an

You might also like