ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
d = {}
try:
d[[1]] = 2
except TypeError as e:
print(type(e).__name__)
print(d)- A. KeyError | {}
- B. None | {}
- C. TypeError | {[2]: 9}
- D. TypeError | {}
Correct answer: D. TypeError | {}
Lists are unhashable, so they cannot be dict keys, and the assignment raises TypeError before the dict changes. The dict stays empty.
More Python Programming questions
- What is printed? python from functools import reduce print(reduce(lambda a, b: a 10 + b, [1, 2, 3]), reduce(lambda a, b: a - b, [10, 2…
- What is printed? python print(sum(x for x in range(1, 11) if x % 2 == 0) - sum(x for x in range(1, 11) if x % 2))
- What is printed? python print('a,b,,c'.split(','), 'a b'.split())
- What is printed? python t = (1, 2) t += (3,) print(t, len(t))
- What is printed? python print(abs(-0), abs(-2.5), -(-3))
- What is printed? python print(hex(255), oct(8), bin(-5))