Find the output of the following program:
Python3
L1 = [ 1 , 2 , 3 , 4 ]
L2 = L1
L3 = L1.copy()
L4 = L1
L1[ 0 ] = [ 5 ]
print (L1, L2, L3, L4)
|
(A)
[5, 2, 3, 4] [5, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
(B)
[[5], 2, 3, 4] [[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4]
(C)
[5, 2, 3, 4] [5, 2, 3, 4] [5, 2, 3, 4] [1, 2, 3, 4]
(D)
[[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4] [[5], 2, 3, 4]
Answer: (D)
Explanation:
List L2 is the Shallow copy of L1, while L3 and L4 are Deep Copy(True Copy) of List L1. L1[0] = [5], implies that at index 0, list [5] will be present and not integer value 5.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
17 Sep, 2020
Like Article
Save Article