ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
d = {}
d[1] = "a"
d[1.0] = "b"
d[True] = "c"
print(d, len(d))- A. {1: 'a', 1.0: 'b', True: 'c'} 3
- B. {1: 'a'} 1
- C. {1: 'c'} 1
- D. {True: 'c'} 1
Correct answer: C. {1: 'c'} 1
1, 1.0 and True are equal and have the same hash, so they are the same dictionary key. The first key object (1) is kept, while the value is overwritten each time, ending as 'c'.
More Python Programming questions
- What is printed? python a = [1, 2, 3, 4, 5, 6] for x in a: if x % 2 == 0: a.remove(x) print(a)
- What is printed? python print(round(2.5), round(3.5), round(-0.5), int(-2.7), -7 // 2, -7 % 2)
- What is printed? python from collections import Counter c = Counter("mississippi") print(c.mostcommon(2), c["z"], sum(c.values()))
- What is printed? python a, b, c = range(6) x, y = y, x = 1, 2 print(a, b, c, x, y)
- What is printed? python words = ["banana", "Apple", "cherry", "apple"] print(sorted(words), sorted(words, key=str.lower)[:2], max(words…
- What is printed? python i = 10 squares = [i i for i in range(3)] for j in range(3): pass print(i, squares, j)