ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
n = 12
print(n & 1 == 0, (n & 1) == 0, n & n - 1 == 0, 8 & 7 == 0)
  1. A. True True False True
  2. B. False True False True
  3. C. True True True True
  4. D. True True False False

Correct answer: A. True True False True

In Python & binds tighter than ==, so n & 1 == 0 means (n & 1) == 0, which is True for 12. n & (n - 1) is 8 for 12, so the power-of-two test fails, while 8 & 7 is 0.

More Python Programming questions

Exams that ask this topic