ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
d = {1: 'a'}
d[1.0] = 'b'
d[True] = 'c'
print(d)- A. {1: 'a', 1.0: 'b', True: 'c'}
- B. {True: 'c'}
- C. {1: 'a'}
- D. {1: 'c'}
Correct answer: D. {1: 'c'}
1, 1.0 and True are equal and hash the same, so they are one key. The dict keeps the first key object and only updates the value, so the output is {1: 'c'}.
More Python Programming questions
- What is printed? python def acc(): total = 0 while True: x = yield total if x is None: return total total += x g = acc() next(g) g.send(5)…
- What is printed? python class P: def init(self, x): self.x = x def eq(self, o): return self.x == o.x try: s = {P(1)} except TypeError…
- What is printed? python class S: slots = ('a',) s = S() s.a = 1 try: s.b = 2 except AttributeError: print('no dict', s.a)
- What is printed? python print(len(set(map(lambda x: x % 3, range(10)))), sum(1 for in filter(None, [0, 1, '', 'a', None])))
- What is printed? python def mpow(b, e, m): r = 1 b %= m while e: if e & 1: r = r b % m b = b b % m e >>= 1 return r print(mpow(2, 10…
- What is printed? python import math n = 1016 - 1 print(math.isqrt(n), int(n 0.5))