ProgrammingVery hardJEE Main · CAT placement

What is printed?

What is printed?
print(1 << 100 >> 99)
try:
    print(1 >> -1)
except ValueError as e:
    print(e)
  1. A. 2
  2. B. 2 negative shift count
  3. C. 1 negative shift count
  4. D. 2 0

Correct answer: B. 2 negative shift count

<< and >> have equal precedence and group left to right, so 1 << 100 >> 99 is 2. Shifting by a negative count raises ValueError with the message 'negative shift count'.

More Python Programming questions

Exams that ask this topic