ProgrammingModerateAccenture · Capgemini pattern

What is printed?

What is printed?
print(int("  -0012 "), int("1_000"), float("1e3"), int("101", 2), int(-2.9))
  1. A. -12 1000 1000 5 -3
  2. B. -12 1000 1000.0 5 -2
  3. C. ValueError
  4. D. -12 1000 1000.0 101 -2

Correct answer: B. -12 1000 1000.0 5 -2

int() ignores surrounding whitespace and leading zeros, accepts a sign and (since 3.6) underscores between digits. float("1e3") is 1000.0. int(s, 2) parses binary: 101 is 5. int() on a float truncates toward zero, so -2.9 becomes -2, not -3.

More Python Programming questions

Exams that ask this topic