# Python Deepcopy: MCQs on Deepcopy & Shallowcopy

Python Deepcopy. Multiple Choice Questions on the topic of Deepcopy and Shallowcopy in Python Programming Language.

## Python Deepcopy

What will be the output of the following code ??

a = [1, 2, 3, 4, 5]
b = lambda x: (b (x[1:]) + x[:1] if x else [])
print(b (a))

a) 1 2 3 4 5
b) [5,4,3,2,1]
c) []
d) Error, lambda functions can’t be called recursively

What is the base case in the Merge Sort algorithm when it is solved recursively ??

a) n=0
b) n=1
c) A list of length one
d) An empty list

What will be the output of the following ??

def check(n):
if n < 2:
return n % 2 == 0
return check(n – 2)
print(check(11))

a) False
b) True
c) 1
d) An exception is thrown

What will be the output ??

l1=[1, 2, 3, (4)]
l2=l1.copy()
l2
l1

a) [1, 2, 3, (4)]
[1, 2, 3, 4]

b) [1, 2, 3, 4]
[1, 2, 3, (4)]

c) [1, 2, 3, 4]
[1, 2, 3, 4]

d) [1, 2, 3, (4)]
[1, 2, 3, (4)]

Python Deepcopy

In which copy, the modification done on one list affects the other list. In which copy, the modification done on one list does not affect the other list ??

a) shallow, deep
b) memberwise, shallow
c) deep, shallow
d) deep, memberwise

What will be the output of the following Python ??

l1=[10, 20, 30, ]
l2=copy.deepcopy(l1)
l1=90
l1
l2

a) [10, 20, 30, ]
[10, 20, 30, 90]

b) Error

c) [10, 20, 30 ]
[10, 20, 30, ]

d) [10, 20, 30, ]
[10, 20, 30, ]

l1=[1, 2, 3, ]
l2=list(l1)
id(l1)==id(l2)

a) True
b) False
c) Error

What will be the output of code ??

l1=[10, 20, 30]
l2=l1
id(l1)==id(l2)

l2=l1.copy()
id(l1)==id(l2)

a) False, False
b) False, True
c) True, True
d) True, False

Python Deepcopy

What will be the output of the following Python code and state the type of copy ??

l1=[2, 4, 6, 8]
l2=[1, 2, 3]
l1=l2
l2

a) [2, 4, 6, 8], shallow copy
b) [2, 4, 6, 8], deep copy
c) [1, 2, 3], shallow copy
d) [1, 2, 3], deep copy

The nested list undergoes shallow copy even when the list as a whole undergoes deep copy ??

a) True
b) False

In which copy, the base address of the objects are copied. In which copy, the base address of the objects are not copied ??

a) deep. shallow
b) memberwise, shallow
c) shallow, deep
d) deep, memberwise

What will be the output of the following Python code ??

l=[2, 3, [4, 5]]
l2=l.copy()
l2=88
l
l2

a) [88, 2, 3, [4, 5]]
[88, 2, 3, [4, 5]]

b) [2, 3, [4, 5]]
[88, 2, 3, [4, 5]]

c) [88, 2, 3, [4, 5]]
[2, 3, [4, 5]]

d) [2, 3, [4, 5]]
[2, 3, [4, 5]]

Which type of copy is shown in the following python code ??

l1=[[10, 20], [30, 40], [50, 60]]
ls=list(l1)
ls
[[10, 20], [30, 40], [50, 60]]

a) Shallow copy
b) Deep copy
c) memberwise
d) All of the mentioned

error: Content is protected !!