ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(1 if [] == [] is True else 0, [] is [], () is ())
  1. A. 0 False True
  2. B. 1 False True
  3. C. 0 True True
  4. D. 0 False False

Correct answer: A. 0 False True

[] == [] is True is a chain: the first comparison is True, but [] is True is False, so the condition is False and the result is 0. Two separate empty lists are distinct objects, while empty tuples are a shared singleton.

More Python Programming questions

Exams that ask this topic