ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(float('  1_000.5 '), float('infinity') > 1e308, float('-nan') != float('-nan'), int(' +0012 '))
  1. A. 1000.5 True False 12
  2. B. 1 000.5 True True 12
  3. C. 1000.5 False True 12
  4. D. 1000.5 True True 12

Correct answer: D. 1000.5 True True 12

float() accepts underscores between digits and ignores surrounding whitespace. Infinity is larger than any finite float, and NaN is never equal to itself, including a NaN with a minus sign. int() also strips whitespace and accepts an explicit plus sign.

More Python Programming questions

Exams that ask this topic