ProgrammingVery hardProduct-company MCQ pattern

What is printed?

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

Correct answer: A. True False False True

Membership tests in a list check identity before equality, so the same nan object is found. A new nan object is not identical to n and is not equal to it, and n == n is False.

More Python Programming questions

Exams that ask this topic