ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(int('1_000') + int('0_1'), '1_000'.replace('_', '') == '1000', float('1_0.5_0'), '%.1f' % float('1_0.5_0'))
  1. A. 1001 True 10.5 10.5
  2. B. 1000 True 10.5 10.5
  3. C. 1001 False 10.5 10.5
  4. D. 1001 True 105 10.5

Correct answer: A. 1001 True 10.5 10.5

Underscores between digits are accepted by int() and float() but not by a plain str comparison, so the replaced text is 1000. Adding int('0_1') gives 1 and the total is 1001.

More Python Programming questions

Exams that ask this topic