ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(len({0.0, -0.0, 1}), hash(1) == hash(1.0) == hash(True))- A. 2 False
- B. 3 False
- C. 2 True
- D. 3 True
Correct answer: C. 2 True
0.0 and -0.0 compare equal and have the same hash, so the set keeps one of them. Equal numbers always hash equal in Python, so 1, 1.0 and True share one hash.
More Python Programming questions
- What is printed? python print(1 == 1.0 == True, {1: 'a'}.get(True))
- What is printed? python print([i j for i, j in zip(range(3), range(3, 0, -1))])
- What is printed? python print(''.join(chr(ord('a') + (ord(c) - ord('a') + 3) % 26) for c in 'xyz'))
- What is printed? python import math print(len(str(math.factorial(200))))
- What is printed? python import bisect print(bisect.bisectleft([1, 1, 1], 1), bisect.bisectright([1, 1, 1], 1))
- What is printed? python print(0.1 0.1 == 0.01, round(0.1 0.1, 2) == 0.01)