ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from collections import defaultdict
d = defaultdict(list)
d['a']
print('a' in d, len(d), d.get('b'), 'b' in d)- A. False 0 None False
- B. True 1 [] False
- C. True 0 None False
- D. True 1 None False
Correct answer: D. True 1 None False
Reading d['a'] on a defaultdict inserts the default value, so the key exists afterwards. get() never inserts, so d.get('b') is None and 'b' is still absent.
More Python Programming questions
- What is printed? python from functools import cache @cache def paths(r, c): return 1 if r == 0 or c == 0 else paths(r - 1, c) + paths(r, c…
- What is printed? python print(sum(map(int, str(2 100))))
- What is printed? python print(bin(12345).count('1'), len(bin(12345)) - 2)
- What is printed? python print(int(float('1e3')), int('12'))
- What is printed? python print('%5.2f|%-4d|%04x' % (3.14159, 7, 255))
- What is printed? python a = {1, 2, 3, 4} b = {3, 4, 5} print(a ^ b, a - b, b <= a, a | b == {1, 2, 3, 4, 5})