Python-Quizzes | Python List Quiz | Question 8
Find the output of the following program:
Python3
list1 = [ 1 , 2 , 3 , 4 , 5 ]
list2 = list1
list2[ 0 ] = 0 ;
print ( list1)
|
(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:
In 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
Please comment below if you find anything wrong in the above post
Last Updated :
17 Sep, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...