ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(-1 >> 1, -1 << 2, -5 >> 10, 5 >> -0 if False else 0)
  1. A. -1 -4 -1 0
  2. B. -1 -4 0 0
  3. C. -2 -4 -1 0
  4. 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

Exams that ask this topic