ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(len(bin(255)), bin(255).count('0'), bin(-255).count('1'))
  1. A. 10 2 8
  2. B. 10 1 8
  3. C. 9 1 8
  4. D. 10 1 9

Correct answer: B. 10 1 8

bin(255) is 0b11111111, which has ten characters. The only zero is inside the 0b prefix, and bin(-255) has eight ones after its minus sign.

More Python Programming questions

Exams that ask this topic