If we make changes to a list passed in as an argument, does it change the list itself?
Without going into too much detail, the general answer is yes, changes to a list that is passed in as an argument for a function can change the list itself.
Say for example, that you had the following function that takes in a list, and changes the value at index
1 to the value
def update_list(lst): lst = 20
When we run this function with any list as an argument, it will change the value being referenced for that list at index
numbers = [1, 2, 3, 4] update_list(numbers) print(numbers) # [1, 20, 3, 4] names = ["Alice", "Bob", "Carl"] update_list(names) print(names) # ["Alice", 20, "Carl"]
The reason for this is that Python lists store references to objects, rather than the objects themselves. So, running this function is changing the reference at index
1 of the lists to be changed to the value