ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(len(bytes(3)), bytes([65, 66]) == b'AB', bytearray(b'ab') == b'ab', type(b'a'[0]).__name__)
- A. 3 True True bytes
- B. 2 True True int
- C. 3 False True int
- D. 3 True True int
Correct answer: D. 3 True True int
bytes(3) is three zero bytes. Indexing a bytes object returns an int, not a one-byte bytes object, and bytearray compares equal to bytes with the same content.
More Python Programming questions
- What is printed? python s = 'abc' t = s s += 'd' print(s, t, s is t)
- What is printed? python a = [1, 2] b = a 2 b[0] = 9 c = a + a c[2] = 7 print(a, b, c)
- 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)