ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
b = "Hé".encode("utf-8")
print(len("Hé"), len(b), b[1], b.decode("latin-1"))- A. 2 2 233 Hé
- B. 2 3 195 Hé
- C. 2 3 233 Hé
- D. 3 3 195 Hé
Correct answer: B. 2 3 195 Hé
'é' takes two bytes in UTF-8 (0xC3 0xA9), so the bytes object has length 3 and b[1] is the int 195. Decoding those bytes as Latin-1 maps each byte to one character, producing the mojibake 'Hé'.
More Python Programming questions
- What is printed? python b = b"abc" print(b[0], b[:1], list(b"hi"), bytes([65, 66]), b"a" + bytearray(b"b"))
- What is printed? python print(chr(ord("a") + 25), ord("A") - ord("a"), "".join(chr(ord(c) ^ 32) for c in "PyThOn"), str(b"x", "ascii"))
- What is printed? python print(min([], default=0), max([2, 7], default=0), min("b", "a", key=ord), sum([[1], [2]], []))
- What is printed? python for kw in [{}, {"strict": True}]: try: print(list(zip("ab", [1, 2, 3], kw)), end=" ") except ValueError…
- What is printed? python def g(): yield from range(2) yield from "ab" return "done" def h(): r = yield from g() yield r print(list(h())…
- What is printed? python def evens(): n = 0 while True: yield n n += 2 def take(k, it): return [next(it) for in range(k)] e = evens()…