Python-Quizzes | Python List Quiz | Question 8

Question 8: Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

list1 = [1, 2, 3, 4, 5
list2 = list1 
  
list2[0] = 0
  
print( list1)  

chevron_right


(A) [1, 2, 3, 4, 5, 0]
(B) [0,1, 2, 3, 4, 5]
(C) [0, 2, 3, 4, 5]
(D) [1, 2, 3, 4, 0]


Answer: (C)

Explanation: n this problem, we have provided a reference to the list1 with another name list2 but these two lists are same which have two references(list1 and list2). So any alteration with list2 will affect the original list

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.