ProgrammingVery hardGATE CS · Product-company placement
Assertion (A): After `t = (1, 2, [3])`, the statement `t[2].append(4)` succeeds and changes what `print(t)` shows. Reason (R): A tuple's immutability means the references it holds cannot be rebound, not that the objects they refer to cannot change.
- A. Both A and R are true, but R is not the correct explanation of A
- B. A is true but R is false
- C. Both A and R are true, and R is the correct explanation of A
- D. A is false but R is true
Correct answer: C. Both A and R are true, and R is the correct explanation of A
t[2] is a list; appending mutates the list object while the tuple still holds the same reference, so print shows (1, 2, [3, 4]). That is exactly the distinction R draws.
More Python Programming questions
- Which of these expressions raises an exception in Python 3?
- Which statement about the C3 method resolution order is correct for class D(B, C) where both B and C inherit from A?
- Which is the safest way to remove every even number from a list nums in place (so that other references to the same list see the change)?
- What is printed? python import sys a = [] b = a c = [a, a] print(sys.getrefcount(a) - sys.getrefcount([]) >= 3, c[0] is c[1], [a] == [b])
- What is printed? python x = (1, 2, 3) y = x + (4,) z = x 0 print(len(y), z, x.count(2), x.index(3), 3 in x)
- What is printed? python s = "a1b22c333" digits = "".join(ch for ch in s if ch.isdigit()) letters = [ch for ch in s if ch.isalpha()]…