ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(3 * [0] == [0, 0, 0], [0] * 3 is [0] * 3, 'a' in 'abc' in 'abcdef')
  1. A. False False True
  2. B. True True False
  3. C. True False True
  4. D. True True True

Correct answer: C. True False True

Two separate list multiplications create different objects, so the is test is False. The chained in checks 'a' in 'abc' and 'abc' in 'abcdef', both True.

More Python Programming questions

Exams that ask this topic