ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
b = b"abc"
print(b[0], b[:1], list(b"hi"), bytes([65, 66]), b"a" + bytearray(b"b"))
  1. A. b'a' b'a' ['h', 'i'] b'AB' b'ab'
  2. B. 97 b'a' [104, 105] b'65 66' b'ab'
  3. C. 97 b'a' [104, 105] b'AB' b'ab'
  4. D. 97 97 [104, 105] b'AB' bytearray(b'ab')

Correct answer: C. 97 b'a' [104, 105] b'AB' b'ab'

Indexing bytes gives an int, slicing gives bytes. Iterating bytes yields ints. bytes([65, 66]) builds from code values. bytes + bytearray returns the type of the left operand, bytes.

More Python Programming questions

Exams that ask this topic