ProgrammingModerateTCS NQT · Infosys pattern

What is printed?

What is printed?
a = 256; b = 256
c = [1, 2]; d = [1, 2]
print(a == b, c == d, c is d, c[:] is c)
  1. A. True True False False
  2. B. True True True False
  3. C. True False False False
  4. D. True True False True

Correct answer: A. True True False False

== compares values: equal ints and equal lists. 'is' compares identity: two list literals create two objects, and slicing creates a new list too. (Avoid relying on 'is' for numbers; small-int caching is an implementation detail.)

More Python Programming questions

Exams that ask this topic