ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(hash(-1), hash(-2), hash(-1) == -2, hash(1) == hash(1.0))
- A. -2 -2 True True
- B. -1 -2 True True
- C. -2 -2 False True
- D. -2 -1 True True
Correct answer: A. -2 -2 True True
CPython reserves -1 as an internal error code for hashing, so hash(-1) is -2. hash(-2) is also -2, and equal numbers such as 1 and 1.0 always share a hash.
More Python Programming questions
- What is printed? python print(232, (23)2, -22, (-2)2, 2-12)
- What is printed? python print(float(254) + 1 == 254, 254 + 1 == float(254), 1e16 + 2 == 1e16 + 1)
- What is printed? python print(int('١٢٣'), int('0' 2 + '5'), int('5' + '0' 2), int(' t7n'))
- What is printed? python print(bin(-8 & 0xFF), (-8) >> 1, (-8) // 2, (-9) // 2, -9 >> 1)
- What is printed? python print(x := 7, x 2, [y := 3, y + 1])
- What is printed? python print('%s|%r' % ("it's", "it's"))