ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(hex(255), hex(-255), oct(-8), bin(0), int('-ff', 16), int('0xFF', 0))
  1. A. 0xff -0xff -0o10 0b0 -255 255
  2. B. 0xff -0xff -0o8 0b0 -255 255
  3. C. 0xff -0xff -0o10 0b1 -255 255
  4. D. 0xff -0xff -0o10 0b0 -255 254

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

hex, oct and bin keep the sign in front of the digits rather than printing two's complement, and int with base 16 accepts a leading minus sign. Base 0 reads the 0x prefix and gives 255.

More Python Programming questions

Exams that ask this topic