ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(bytes('é', 'utf-8'), 'é'.encode('latin-1'), len('é'.encode('latin-1')) == len('é'.encode('utf-8')))- A. b'\xc3\xa9' b'\xc3\xa9' False
- B. b'\xc3\xa9' b'\xe9' False
- C. b'\xe9' b'\xc3\xa9' True
- D. b'\xc3\xa9' b'\xe9' True
Correct answer: B. b'\xc3\xa9' b'\xe9' False
In UTF-8 é is the two bytes c3 a9, while Latin-1 stores it as the single byte e9. The byte counts differ, so the final comparison is False.
More Python Programming questions
- What is printed? python print(round(-0.5), round(0.5), round(1.5), round(-1.5), round(2.5))
- What is printed? python x = [3, 1, 2] print(sorted(x, reverse=True)[:2], x[::-1][1:], list(reversed(sorted(x))))
- What is printed? python print('%08.2f' % -1.5, '%+08d' % 42, '%-+5d|' % 7, '%x' % -255)
- What is printed? python print(2 10 == 1024, 2 10 == 1 << 10, 10 2 3, (10 2) 3)
- What is printed? python from itertools import accumulate print(list(accumulate([1, 2, 3], lambda a, b: a b)), list(accumulate('ab'…
- What is printed? python print(sorted({'b': 1, 'a': 1}.items()), list({3: 'x', 1: 'y'}), dict(zip('ab', [1, 2])), dict.fromkeys('ab', 0))