Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 11)
11.
What is the output of the following Python code?
def modify_list(my_list):
    my_list[0] = 5

original_list = [1, 2, 3]
modify_list(original_list.copy())
print(original_list)
[1, 2, 3]
[5, 2, 3]
This code will result in an error.
[1, 2, 3, 5]
Answer: Option
Explanation:
The modify_list function modifies a copy of the list, not the original list.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.