ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(int('10', 2), int('0o17', 0), int('17', 8), int('0x_ff', 16))
  1. A. 2 15 17 255
  2. B. 2 17 15 255
  3. C. 2 15 15 0
  4. D. 2 15 15 255

Correct answer: D. 2 15 15 255

int() with base 2 reads 10 as 2, and base 0 reads the 0o prefix as octal, so 17 octal is 15. Base 8 reads 17 as octal, and an underscore may follow the 0x prefix in int(), giving 255.

More Python Programming questions

Exams that ask this topic