ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(int.bit_length(-255), (255).bit_length(), (256).bit_length())
  1. A. 8 8 8
  2. B. 9 8 9
  3. C. 8 8 9
  4. D. 7 8 9

Correct answer: C. 8 8 9

bit_length works on the absolute value, so -255 needs 8 bits. 255 fits in 8 bits, while 256 needs 9.

More Python Programming questions

Exams that ask this topic