ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(-1 >> 1, -1 << 2, -5 >> 10, 5 >> -0 if False else 0)
- A. -1 -4 -1 0
- B. -1 -4 0 0
- C. -2 -4 -1 0
- D. 0 -4 -1 0
Correct answer: A. -1 -4 -1 0
Right shifting a negative int keeps the sign, so -1 stays at -1 and -5 >> 10 is also -1. Left shifting -1 by 2 multiplies by 4.
More Python Programming questions
- What is printed? python print(bin(-1 & 0b111), (-1) & 0xF == 15, -16 >> 2, -15 >> 2)
- What is printed? python print(''.join(sorted(set('mississippi'))), ''.join(sorted('mississippi', key=lambda c: (-'mississippi'.count(c)…
- What is printed? python print(str(1.1 1.1), str(1.21), 1.1 1.1 == 1.21, abs(1.1 1.1 - 1.21) < 1e-12)
- What is printed? python print(10 2 == 100.0, 2 0.5 2 == 2 0.25, pow(4, 0.5))
- What does ','.join([1, 2]) do in Python 3?
- Which statement about the heapq module is correct?