Python Programming - Tricky Questions - Discussion

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

original_list = [1, 2, 3]
modify_list(original_list)
print(original_list)
[0, 1, 2]
[1, 2, 3]
This code will result in an error.
None
Answer: Option
Explanation:
The function reassigns my_list to a new list, but it does not modify the original list outside the function.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.