Answer to Question #282090 in Python for kika

Question #282090

Create your own example of a function that modifies a list passed in as an argument. Describe what your function does in terms of argumentsparametersobjects, and references


1
Expert's answer
2021-12-22T14:17:53-0500
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])

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS