Question #152574

Finally, 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.

Expert's answer

def append_four(lst: list):
    lst.append(4)

a = [1, 2, 3]
append_four(a)
print(a)  # [1, 2, 3, 4]

When append_four is called, a list object is passed into the function as argument. Parameter lst contains the reference to the object. append_four calls the method append of the object.


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!

LATEST TUTORIALS
APPROVED BY CLIENTS