ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
nan = float("nan")
L = [nan]
print(nan == nan, nan in L, L == [nan], [float("nan")] == [float("nan")])
  1. A. False True True False
  2. B. False False False False
  3. C. False True False False
  4. D. True True True True

Correct answer: A. False True True False

Container membership and equality first check identity (x is y) before ==. The same nan object is found in L and makes L == [nan] true, but two separately created nans are different objects that compare unequal.

More Python Programming questions

Exams that ask this topic