ProgrammingModerateTCS NQT · Infosys

What is printed?

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

Correct answer: B. x xy False

Concatenation builds a new string, and s is rebound to it. t still refers to the old 'x' object, so the two names are no longer the same object.

More Python Programming questions

Exams that ask this topic