ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(len('héllo'.encode('utf-8')), len('héllo'.encode('utf-16')), len('héllo'))- A. 6 12 5
- B. 6 10 5
- C. 8 12 5
- D. 6 12 6
Correct answer: A. 6 12 5
The é takes two bytes in UTF-8, so the text is 6 bytes. UTF-16 adds a two-byte byte-order mark and uses two bytes per code unit, giving 2 + 5 * 2 = 12. len counts code points, which is 5.
More Python Programming questions
- What is printed? python print('abc' < 'abd', 'Z' < 'a', '10' < '9', [10] < [9], (1, 'b') < (1, 'a'))
- What is printed on the second line? python print(''.join(sorted('banana'))) print(sorted('Banana', key=str.lower)) print(sorted(['b10'…
- What is printed? python print(min([3, 1.0, True]), max([1, True, 1.0]), max([True, 1.0]), min([1.0, True]))
- What is printed? python print(list(range(10, 0, -3)), range(0, 10, 3)[-1], len(range(5, 1)), range(3) == range(0, 3, 1), range(0, 6, 2) ==…
- What is printed? python print(sum(range(106)) == 106 (106 - 1) // 2, 20.5 20.5 == 2.0, 20.5 20.5)
- What is printed? python print(int(2.9999999999999996), float('1e400'), -float('1e400'), 1e308 10 == float('inf'))