ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
s = 'abc'
t = s
s += 'd'
print(s, t, s is t)
  1. A. abcd abc False
  2. B. abcd abcd True
  3. C. abc abc False
  4. D. abcd abc True

Correct answer: A. abcd abc False

Strings are immutable, so += creates a new object and rebinds s. The name t still refers to the original 'abc' object, so the two names no longer point to the same object.

More Python Programming questions

Exams that ask this topic