CBSE Class 12 Computer Science Question 93 of 103

Working with Functions — Question 26

Back to all questions
26
Question

Question 19(ii)

What is the output of following code fragments ?

def increment(n):
    n.append([49])
    return n[0], n[1], n[2], n[3]
L = [23, 35, 47]
m1, m2, m3, m4 = increment(L)
print(L)
print(m1, m2, m3, m4)
print(L[3] == m4)
Answer
Output
[23, 35, 47, [49]]
23 35 47 [49]
True
Explanation

The function increment appends [49] to list n and returns its first four elements individually. When L = [23, 35, 47], calling increment(L) modifies L to [23, 35, 47, [49]]. Variables m1, m2, m3, and m4 are assigned the same list [23, 35, 47, [49]], representing the original list L. Thus, printing L and m1, m2, m3, m4 yields [23, 35, 47, [49]]. The expression L[3] == m4 evaluates to True, indicating that the fourth element of L is the same as m4.