ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(int('0x1F', 16), int('1F', 16), int('0b101', 0), int(' 42 '), int('4_2'))
  1. A. 31 31 5 42 4_2
  2. B. 31 31 0 42 42
  3. C. 31 31 5 42 42
  4. D. ValueError

Correct answer: C. 31 31 5 42 42

int() accepts a 0x prefix when the base is 16, underscores between digits in any base, and surrounding whitespace. The base-0 call infers the 0b prefix and reads 101 as 5.

More Python Programming questions

Exams that ask this topic