# Author: James Tam # Version: March, 2013 # Learning concepts: # Pass by reference (passing a reference to a list) # fun2(1DList) # returns(1DList) # Modify list # Return copy of reference back to caller # fun1(): The return statement is not needed because the list # is passed by reference. (Passing ‘aListCopy’ as a parameter def fun1(aListCopy): aListCopy[0] = aListCopy[0] * 2 aListCopy[1] = aListCopy[1] * 2 return aListCopy # Modify list # Because aList copy refers to the list in 'start()' the return # isn't needed # fun2(1DList) # returns(nothing) # fun2(): a better programming convention is employed. The # approach taken in fun2() used be employed rather than the # one taken in fun1() def fun2(aListCopy): aListCopy[0] = aListCopy[0] * 2 aListCopy[1] = aListCopy[1] * 2 # start(none) # returns(nothing) def start(): aList = [2,4] print("Original list in start() before function calls:\t", end="") print(aList) aList = fun1(aList) print("Original list in start() after calling fun1():\t", end="") print(aList) fun2(aList) print("Original list in start() after calling fun2():\t", end="") print(aList) start()