ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(list('abc'.encode()), 'abc'.encode()[0] + 1, bytes('hi', 'ascii') == b'hi')
  1. A. [97, 98, 99] 98 False
  2. B. [97, 98, 99] 98 True
  3. C. [97, 98, 99] 99 True
  4. D. [97, 99] 98 True

Correct answer: B. [97, 98, 99] 98 True

Iterating over a bytes object gives ints, so the code points 97, 98 and 99 are printed. Indexing gives the int 97, and bytes built from ASCII text equal the matching b'' literal.

More Python Programming questions

Exams that ask this topic