ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(True & 2, True | 2, True ^ True, ~True)
  1. A. 0 3 True -2
  2. B. 0 2 False -2
  3. C. 1 3 False -2
  4. D. 0 3 False -2

Correct answer: D. 0 3 False -2

True acts as 1 in bitwise operations, so 1 & 2 is 0 and 1 | 2 is 3. True ^ True is False, and ~True applies the integer complement to 1, which is -2.

More Python Programming questions

Exams that ask this topic