ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(float('  1_0.5  '), float('infinity'), float('-nan') != float('-nan'), float('1_0'))
  1. A. 10.5 inf False 10.0
  2. B. 105.0 inf True 10.0
  3. C. 10.5 inf True 10.0
  4. D. 10.5 nan True 10.0

Correct answer: C. 10.5 inf True 10.0

float() strips surrounding whitespace, accepts underscores between digits, and recognises 'infinity'. NaN never equals anything, so comparing it with itself gives True for !=.

More Python Programming questions

Exams that ask this topic