Create your own example of a function that modifies a list passed in as an argument. Describe what your function does in terms of arguments, parameters, objects, and references.
def manipulateList(list1):
#define a reference made of list1
a = list1
#assign it to a variable b
b = a
#add more values to list a
a.append(20)
#print the lists
print('b', b)
print('a', a)
#reverse the list
a.reverse()
#print the lists
print('b', b)
print('a', a)
#create a new list
a = [12,13,14,15]
print('b', b)
print('a', a)
manipulateList([1,2,3,4,5])
Comments
Leave a comment