ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(4 & 3 == 0, 6 & 3 == 0)
  1. A. True False
  2. B. False False
  3. C. True True
  4. D. False True

Correct answer: A. True False

In Python the bitwise & binds tighter than ==, so this is (4 & 3) == 0 and (6 & 3) == 0. 4 & 3 is 0, and 6 & 3 is 2, which is not 0. In C the precedence is reversed, which is a common trap for Python programmers coming from C.

More Python Programming questions

Exams that ask this topic