ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
print(hash(-1) == hash(-2), hash(-1), hash(2**61 - 1))
- A. False -1 0
- B. True -2 0
- C. True -1 1
- D. True -2 2305843009213693951
Correct answer: B. True -2 0
CPython reserves -1 as an error marker for hashes, so hash(-1) is -2, which is also hash(-2). Integers are hashed modulo 2**61 - 1, so 2**61 - 1 hashes to 0.
More Python Programming questions
- What is printed? python print(int.bitlength(-255), (255).bitlength(), (256).bitlength())
- What is printed? python print(chr(0x1F600) == '😀', len('😀'), len('😀'.encode('utf-16-le')))
- What is printed? python print(10400 > float('inf'), float('inf') > 10400, float(10308) == 10308)
- What is printed? python print('ab' in ['a', 'ab'], 'ab' in 'a,ab'.split(','), 'a' in 'abc' and 'ac' in 'abc')
- What is printed? python print(f'{-5:x}', f'{-5 & 0xF:x}', hex(-255), format(255, '#010b'))
- What is printed? python students = [('Ravi', 88), ('Asha', 92), ('Bala', 88), ('Chitra', 92)] print([n for n, s in sorted(students…