ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(len('é'), len('é'.encode()), len(f'{"é":>3}'), len(str(0.1 + 0.2)))
  1. A. 1 2 1 19
  2. B. 1 2 3 17
  3. C. 1 3 3 19
  4. D. 1 2 3 19

Correct answer: D. 1 2 3 19

é is one code point but two UTF-8 bytes. The f-string pads it to width three, and str(0.1 + 0.2) is '0.30000000000000004', which has 19 characters.

More Python Programming questions

Exams that ask this topic