ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(-6 & 0xFF, -6 | 3, -6 ^ -3, ~-6 >> 1)
- A. 250 -1 7 2
- B. 250 -5 7 3
- C. -6 -5 7 2
- D. 250 -5 7 2
Correct answer: D. 250 -5 7 2
Python ints behave as infinite two's complement, so -6 & 0xFF keeps the low byte 250. -6 | 3 is -5, -6 ^ -3 is 7, and ~-6 is 5, so 5 >> 1 = 2.
More Python Programming questions
- What is printed? python print(len('ab' 3 0 + 'c'), ('%5.2f' % 3.14159).strip(), '%-5s|' % 'ab', '%05d' % -42)
- What is printed? python print(-7 // 2, -7 % 2, -7 // 2 2 + -7 % 2)
- What is printed? python print(7 // -2, -7 // 2, 7 % -2, divmod(-7, -2))
- What is printed? python print(round(2.5), round(3.5), round(-0.5), round(0.5 + 1e-16))
- What is printed? python print('ß'.upper(), 'Dž'.lower(), len('ß'.upper()), 'İ'.lower() == 'i')
- What is printed? python import math print(f'{-0.0}', -0.0 == 0.0, math.copysign(1, -0.0))