ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
t = (1, 2, 3) t += (4,) u = t t *= 2 print(t, u, t is u, len(t) * len(u))
- A. (1, 2, 3, 4, 1, 2, 3, 4) (1, 2, 3, 4, 1, 2, 3, 4) False 64
- B. (1, 2, 3, 4, 1, 2, 3, 4) (1, 2, 3, 4) True 32
- C. (1, 2, 3, 4) (1, 2, 3, 4) False 16
- D. (1, 2, 3, 4, 1, 2, 3, 4) (1, 2, 3, 4) False 32
Correct answer: D. (1, 2, 3, 4, 1, 2, 3, 4) (1, 2, 3, 4) False 32
Tuples are immutable, so t *= 2 builds a new tuple and rebinds t, while u keeps the old object. Lists would behave differently because *= changes them in place.
More Python Programming questions
- What is printed? python lst = [1, 2, 3] lst2 = lst lst = 2 lst2 += [9] print(lst, lst2, lst is lst2)
- What is printed? python print(f'{0.1 + 0.2:.17g}', f'{1/7:.10f}', f'{100/3:.0f}', f'{2.345:.2f}')
- What is printed? python a = [3, 1, 2] b = sorted(a, key=lambda x: -x) a.sort(reverse=True) print(a == b, a, b)
- What is printed? python print(pow(7, 222, 10), pow(7, 222, 1000), 7222 % 1000, pow(-7, 3, -5))
- What is printed? python print(int(True) + int('0b11', 2), int(3.7 // 1), int(-0.5), round(-0.5), round(0.5))
- What is printed? python n = 0b10110000 print(n & -n, n & (n - 1), bin(n >> 4), n.bitcount())