# Change local copy of integer def fun1(tempNum): tempNum = tempNum * 2 print("tempNum %d" %tempNum) # Change local copy of integer but the current value of # local passed back to caller. def fun2(tempNum): tempNum = tempNum * 2 print("tempNum %d" %tempNum) return(tempNum) # Create a new list and return reference to new list def fun3(): aList = ["a","b","c"] return(aList) # Unnecessary to pass list as parameter and return def fun4(aList): aList = ["X","Y","Z"] return(aList) # At start we have reference to list in start(), "pass by # reference" for lists in Python def fun5(tempList): # With the reference we can the list in start() tempList[1] = 7 tempList[2] = 13 # At start we have reference to list in start(), "pass by # reference" for lists in Python def fun6(tempList): # This creates a new list and address of list in # start() lost because it's overwritten with the list # that is local to fun6(). # JT: be careful that you don't do this, likely it is # a logic error in your program. tempList = [3,2,1] print("Displays only local list", end =" ") print(tempList) def fun7(localReference): aList = localReference size = len(localReference) for i in range (0,size,1): aList.append(localReference[size-i-1]) def start(): aNum = 8 aList = [1,2,3] print(aNum) print("In effect pass by value for integers in Python") fun1(aNum) print(aNum) print("With anything but lists must return changes") aNum = fun2(aNum) print(aNum) input("Hit enter to continue") print(aList) aList = fun3() print(aList) aList = fun4(aList) print(aList) fun5(aList) print("List before fun6 ", end = " ") print(aList) fun6(aList) print("List after fun6 ", end = " ") print(aList) aList = [1,2,3] print("List reference before fun7()", end = "\t") print(aList) fun7(aList) print("List reference after fun7()", end = "\t") print(aList) aList = [1,2,3] start()