ProgrammingHardCognizant GenC · TCS NQT
What is printed?
What is printed?
d = {'a': {'b': 1}}
print(d.get('a', {}).get('c', 0), d.get('x', {}).get('b'), d['a'].get('b'))- A. 0 0 1
- B. 0 None 1
- C. 0 None 0
- D. None None 1
Correct answer: B. 0 None 1
Each get on an inner dict uses a default. The missing outer key x falls back to an empty dict, so its get returns None, while key b in a is 1.
More Python Programming questions
- What is printed? python import math def ndiv(n): c = 0 for i in range(1, math.isqrt(n) + 1): if n % i == 0: c += 1 if i i == n else 2…
- What is printed? python class N: def init(self, v, nxt=None): self.v, self.nxt = v, nxt def mid(h): slow = fast = h while fast and…
- What is printed? python from collections import Counter print(''.join(c n for c, n in Counter('tree').mostcommon()))
- What is printed? python import itertools print(len(set(itertools.permutations('aab'))), len(list(itertools.permutations('aab'))))
- What is printed? python print(list(zip([iter(range(6))] 2)))
- What is printed? python print(sum(range(106)) % 7)