ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(set([1, 2]) == {1.0, 2.0}, {1: 'x'}.get(1.0), {'1': 2}.get(1))- A. True x 2
- B. True x None
- C. False x None
- D. True None None
Correct answer: B. True x None
Sets and dicts look up keys by hash and equality, so 1.0 finds the key 1. The string key '1' is not equal to the int 1, so get returns None.
More Python Programming questions
- What is printed? python print(2 63 - 1 == 9223372036854775807, (2 63) % 10, -2 63 // 10)
- What is printed? python print(str(10 15 / 10), str(10 16 / 10), 10 16 // 10)
- What is printed? python print('%.3g' % 0.0001234, '%.3g' % 123456.0, '%g' % 0.5)
- What is printed? python print(max('7', '10'), max(7, 10), min('7', '10'), '7' > '10')
- What is printed? python print(len(f'{3.5:>8.2f}'), f'{-3.5:08.1f}', f'{12:#06x}', f'{7:+05d}')
- What is printed? python print('abc'.encode() == b'abc', b'abc'.decode() == 'abc', 'é'.encode('utf-8') == b'xc3xa9', len(b'xc3xa9'.decode()))