ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(oct(-8), hex(-255), bin(0), format(-5, 'b'))
  1. A. -0o10 -0xff 0b0 -101
  2. B. -0o10 -0xff 0b1 -101
  3. C. -8 -0xff 0b0 -101
  4. D. -0o10 -0xff 0 -101

Correct answer: A. -0o10 -0xff 0b0 -101

oct, hex and bin keep the minus sign for negative numbers and add their prefix after it. bin(0) is 0b0, and the b format gives -101 for -5.

More Python Programming questions

Exams that ask this topic