ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(bin(5 & -5), (5).bit_count(), (-5).bit_count(), (-5).bit_length())
  1. A. 0b1 2 2 2
  2. B. 0b1 2 2 3
  3. C. 0b101 2 2 3
  4. D. 0b1 2 0 3

Correct answer: B. 0b1 2 2 3

5 & -5 isolates the lowest set bit of 5, which is 1. bit_count and bit_length use the magnitude of -5, which is 101 in binary, so 2 bits are set and 3 bits are needed.

More Python Programming questions

Exams that ask this topic