ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(hash(1) == hash(1.0), hash(True) == 1, {1: 'a', 1.0: 'b', True: 'c'})- A. True True {1: 'a', 1.0: 'b', True: 'c'}
- B. False True {1: 'c'}
- C. True True {1: 'a'}
- D. True True {1: 'c'}
Correct answer: D. True True {1: 'c'}
1, 1.0 and True hash equally and compare equal, so they are the same dict key. The dict keeps the first key object (1) and overwrites its value with 'c'.
More Python Programming questions
- What is printed? python print(0.1 3 == 0.3, 0.1 3, 0.3 3 == 0.9)
- What is printed? python inf = float('inf') print(inf > 10400, inf - inf == 0, -inf < -10400, inf == inf)
- What is printed? python print(len(str(21000)), sum(int(d) for d in str(2100)))
- What is printed? python import math print(math.gcd(0, -6), math.lcm(4, 6), -7 % -3, math.lcm(0, 5))
- What is printed? python x = 6 print(x & (x - 1), x & -x, (x ^ (x >> 1)) & 1, x.bitlength(), (-x).bitlength())
- What is printed? python print(bin(10 ^ 6), 10 ^ 6 ^ 6, 3 ^ 5 ^ 3 ^ 5, ~-1, -~1)