ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print([int(t, 0) for t in " 12_000 \t-0b101  +7 ".split()])
  1. A. [12000, -5, 7]
  2. B. [12000, -101, 7]
  3. C. [12, -5, 7]
  4. D. ValueError

Correct answer: A. [12000, -5, 7]

split() with no argument breaks on any run of whitespace. int(s, 0) picks the base from the prefix (0b means binary), allows a sign and allows underscores between digits, so -0b101 is -5 and 12_000 is 12000.

More Python Programming questions

Exams that ask this topic