DOC PREVIEW
TAMU CSCE 110 - advanced-functions
Type Miscellaneous
Pages 7

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSCE 110 — Programming IAdvanced FunctionsDr. Tiffani L. WilliamsDepartment of Computer Science and EngineeringTexas A&M UniversityFall 2011Nested Functions (1)1 def foo ():2 m = 33 def bar ():4 n = 45 print m + n6 print m7 bar ()8 foo ()9 print ’ Goodbye !’ Nested Functions (2)1 m = 402 def foo ():3 n = 104 def bar ():5 n = 56 print m + n7 print m + n8 bar ()9 foo ()10 print ’ Goodbye !’ Keyword/Default Arguments (1)1 # Function definition is here2 def printi nf o ( name , age ):3 " This prints a passed info into this func tion "4 print " Name :", name5 print "Age : " , age67 # Now you can call printinfo function8 print ’ F unction call #1 ’9 printi nf o (50 , " miki ")1011 print ’\ nF unction call #2 ’12 printi nf o ( age =50 , name =" miki " ) Keyword/Default Arguments (2)1 # Func tion def in it io n is here2 def printi nf o ( name , age = 35):3 " This prints a passed info into this function "4 print " Name :" , name5 print " Age:", age67 # Now you can call printinfo function8 print ’ F unction call #1 ’9 printi nf o ( age = 50 , name = " miki " )1011 print ’\ nF unction call #2 ’12 printi nf o ( name = " miki ") Changing Parameters I1 # Func tion def in it io n is here2 def chan geme ( mylist ):3 mylist . sort ()4 print ’ Values inside chan geme (): ’, mylist56 def change me 2 ( mylist ):7 mylist . append (12) # same as mylist += [12]8 mylist . sort ()9 print ’ Values inside changeme 2 (): ’ , mylist1011 def change me 3 ( mylist ):12 mylist = mylist + [12]13 mylist . sort ()14 print ’ Values inside changeme 3 (): ’ , mylist151617 # Now you can call change me function18 mylist = [19 , 5, 87, 32]Changing Parameters II19 print ’\ nmylist values :’, mylist20 chan geme ( mylist )21 print ’ Values outside the functi on : ’ , mylist2223 mylist = [19 , 5 , 87 , 32]24 print ’\ nmylist values :’, mylist25 change me 2 ( mylist )26 print ’ Values outside the functi on : ’ , mylist2728 mylist = [19 , 5 , 87 , 32]29 print ’\ n ’30 print ’\ nmylist values :’, mylist31 change me 3 ( mylist )32 print ’ Values outside the functi on : ’ , mylist


View Full Document

TAMU CSCE 110 - advanced-functions

Type: Miscellaneous
Pages: 7
Documents in this Course
06-IO

06-IO

29 pages

21-OOP

21-OOP

8 pages

key

key

6 pages

21-OOP

21-OOP

8 pages

Load more
Download advanced-functions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view advanced-functions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view advanced-functions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?