ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
t = (1, [2, 3], 4)
try:
t[1] += [5]
except TypeError as e:
print("error", end=" ")
print(t)- A. (1, [2, 3, 5], 4)
- B. error (1, [2, 3], 4)
- C. error (1, [2, 3, 5], 4)
- D. (1, [2, 3], 4)
Correct answer: C. error (1, [2, 3, 5], 4)
t[1] += [5] first extends the list in place (lists support +=), then tries to store the result back into the tuple slot, which raises TypeError. The list was already mutated, so the tuple shows [2, 3, 5] despite the error.
More Python Programming questions
- What is printed? python def f(): try: return "try" finally: print("finally", end=" ") def g(): try: return "try" finally: return "finally"…
- What is printed? python nums = [3, 1, 2] r = nums.sort() s = sorted(nums, reverse=True) print(r, nums, s)
- What is printed? python x = 10 def outer(): x = 20 def inner(): nonlocal x x += 1 return x return inner() + x print(outer(), x)
- What is printed? python d = {} d[1] = "a" d[1.0] = "b" d[True] = "c" print(d, len(d))
- What is printed? python a = [1, 2, 3, 4, 5, 6] for x in a: if x % 2 == 0: a.remove(x) print(a)
- What is printed? python print(round(2.5), round(3.5), round(-0.5), int(-2.7), -7 // 2, -7 % 2)