ProgrammingVery hardCodeforces-style · placement coding round
What is printed?
What is printed?
print(hash(1) == hash(True), hash(-1) == -2)
- A. True False
- B. False True
- C. True True
- D. False False
Correct answer: C. True True
bool is a subclass of int and True equals 1, so their hashes match. In CPython hash(-1) is -2, because -1 is reserved as an error marker.
More Python Programming questions
- Which statement about dictionary iteration order in Python 3.7 and later is correct?
- What is printed? python class Q: def init(self): self.i, self.o = [], [] def push(self, x): self.i.append(x) def pop(self): if not self.o…
- What is printed? python print([y for x in [[1, 2], [3], []] for y in x if y % 2])
- What is printed? python out = [] for i in range(3): try: if i == 1: continue out.append(i) finally: out.append('f') print(out)
- What is printed? python print(int('0x1f', 16), int('1f', 16), int('0o17', 8))
- What is printed? python print(divmod(-9, 4), -9 % 4, round(-9 / 4))