ProgrammingVery hardProduct-company MCQ pattern

What is printed?

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

Correct answer: C. False True False True False

NaN is not equal to anything, including itself, so a == a is False. The identity test a is a is True, and list comparison checks identity before equality, so [a] == [a] is True while [b] == [a] is False.

More Python Programming questions

Exams that ask this topic