ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print({'a': 1} | {'a': 2, 'b': 3}, {'a': 1} | {}, dict(a=1) == {'a': 1})- A. {'a': 1, 'b': 3} {'a': 1} True
- B. {'a': 2, 'b': 3} {'a': 2} True
- C. {'a': 2, 'b': 3} {'a': 1} True
- D. {'a': 2, 'b': 3} {'a': 1} False
Correct answer: C. {'a': 2, 'b': 3} {'a': 1} True
The | operator merges dicts, and values from the right operand win when keys clash. Merging with an empty dict leaves the left dict unchanged, and dict(a=1) equals the literal.
More Python Programming questions
- What is printed? python print(format(1234567.891, ',.2f'), format(0.000123, 'e'), format(12, '>5'), format(3, '03'))
- What is printed? python print((1 + 2j) (3 - 1j), abs(3 + 4j), (1 + 2j).conjugate())
- What is printed? python print(list(zip([1, 2, 3], 'ab')), list(zip('ab', [1, 2, 3], [True])), len(list(zip())))
- What is printed? python try: list(zip([1, 2], [3], strict=True)) except ValueError: print('length mismatch') print(list(zip([1, 2], [3])))
- What is printed? python print([f'{i}{ch}' for i, ch in enumerate('ab', 1)])
- What is printed? python from itertools import groupby print([(k, len(list(g))) for k, g in groupby('aabbaa')])