ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: D. False True

NaN is not equal to itself under == in Python, so the first check is False. inf - inf is NaN, which is also unequal to itself, so the second comparison is True.

More Python Programming questions

Exams that ask this topic