ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(-1 & 0xFF, -8 >> 1, -1 >> 100, -9 & 7)
- A. 255 -4 -1 -9
- B. -1 -4 -1 7
- C. 255 -4 -1 7
- D. 255 -5 -1 7
Correct answer: C. 255 -4 -1 7
Python ints act like infinite two's complement, so -1 & 0xFF keeps the low eight bits (255), -8 >> 1 is -4, shifting -1 right stays -1, and -9 & 7 is 7 because -9 ends in the bits 0111.
More Python Programming questions
- What is printed? python print(1 << 64 == 264, (1 << 64) - 1 & 0xFFFF)
- What is printed? python print(0.1 + 0.2 == 0.3, round(0.1 + 0.2, 10) == 0.3, 0.1 + 0.2)
- What is printed? python print(round(2.5), round(3.5), round(-0.5), round(2.675, 2), round(1.005, 2))
- What is printed? python a = float('nan') b = float('nan') print(a == a, a is a, a == b, [a] == [a], [b] == [a])
- What is printed? python print(253 + 1 == 253 + 1.0, 253 + 1 == 253, float(253 + 1) == 253)
- What is printed? python pairs = [(2, 'b'), (1, 'z'), (2, 'a'), (1, 'y')] print(sorted(pairs, key=lambda t: t[0])) print(sorted(pairs…