Question discussion

What is the output of the following Python code?d = {} d[1] = "a" d[1.0] = "b" d[True] = "c" print(len(d), d[1])

1715Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following Python code?

d = {}
d[1] = "a"
d[1.0] = "b"
d[True] = "c"
print(len(d), d[1])
  • A1 c
  • B3 a
  • C2 b
  • D1 a
Correct answer: A

Explanation

1, 1.0 and True are equal and have the same hash, so they are the same key; the dictionary keeps one entry whose value is the last assigned, 'c'.

Discussion 0

Nobody has replied yet. Start the discussion!