ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(len('é'.encode('utf-8')), len('é'.encode('utf-16-le')), len('a€'.encode()), b'\xc3\xa9'.decode())- A. 2 2 3 é
- B. 1 2 4 é
- C. 2 4 4 é
- D. 2 2 4 é
Correct answer: D. 2 2 4 é
é takes two bytes in UTF-8 and two in UTF-16 little-endian. The euro sign takes three bytes in UTF-8, so 'a€' takes one plus three, and the byte pair c3 a9 decodes back to é.
More Python Programming questions
- What is printed? python print(f"{12:>{5}}|{3.14159:.{2}f}|{'ab':^6}")
- What is printed? python x = 12 print(x & -x, x ^ (x - 1), (x & (x - 1)) == 0, -x & x == x & -x)
- What is printed? python print((-5).tobytes(2, 'big', signed=True).hex(), int.frombytes(b'xffxfb', 'big', signed=True)…
- What is printed? python import math print(math.fsum([0.1] 10) == 1.0, sum([0.1] 10) == 1.0, math.isqrt(10 30 - 1))
- What is printed? python print(sorted(['pear', 'Fig', 'apple', 'banana', 'kiwi'], key=lambda s: (len(s), s.lower())))
- What is printed? python print(sorted([('b', 1), ('a', 1), ('c', 2)], key=lambda t: t[1], reverse=True))