ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(b'abc'[0], b'abc'[0:1], len('é'.encode()))
  1. A. 'a' b'a' 2
  2. B. 97 b'a' 1
  3. C. 97 'a' 2
  4. D. 97 b'a' 2

Correct answer: D. 97 b'a' 2

Indexing bytes returns an int, 97. Slicing returns bytes, b'a'. The letter é takes two bytes in UTF-8.

More Python Programming questions

Exams that ask this topic