ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
a = [1, 2] b = a * 2 b[0] = 9 c = a + a c[2] = 7 print(a, b, c)
- A. [9, 2] [9, 2, 1, 2] [1, 2, 7, 2]
- B. [1, 2] [9, 2, 1, 2] [1, 2, 7, 2]
- C. [1, 2] [9, 2, 1, 2] [1, 2, 1, 7]
- D. [1, 2] [1, 2, 1, 2] [1, 2, 7, 2]
Correct answer: B. [1, 2] [9, 2, 1, 2] [1, 2, 7, 2]
a * 2 and a + a both build new lists, so changing b or c never affects a. Item assignment changes only the list it is applied to, so only b[0] and c[2] change.
More Python Programming questions
- What is printed on the first line? python grid = [[0] 2] 2 grid[0][0] = 1 print(grid) g2 = [[0] 2 for in range(2)] g2[0][0] = 1 print(g2)
- What is printed? python t = (1, [2]) t[1].append(3) print(t, len(t)) try: t[0] = 5 except TypeError as e: print(type(e).name)
- What is printed? python print(bin(0b1010 << 2 >> 1 & 0xF), 0o17 + 0x1F + 0b11, 0xff, 10j)
- What is printed? python x = 0 x |= 1 << 3 x &= ~(1 << 0) x ^= 0b111 print(x, x.bitcount(), (x >> 1) & -x)
- What is printed? python print(-(-231) // 1, (231 - 1) & -(231), 231 >> 31, 232 & -232)
- What is printed? python print((1 << 3) - 1 << 2, 1 << 3 - 1 << 2, 1 + 2 << 1, 3 & 2 2)