ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(7 & ~1, 7 >> 1 << 1, (7 | 8) & 12, 6 ^ 3 ^ 3)
  1. A. 6 7 12 6
  2. B. 6 6 12 6
  3. C. 6 6 8 6
  4. D. 6 6 12 3

Correct answer: B. 6 6 12 6

Clearing bit 0 of 7 gives 6, and shifting 7 right then left also drops the low bit. XOR with the same value twice cancels it out, so 6 ^ 3 ^ 3 is 6.

More Python Programming questions

Exams that ask this topic