🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: References and Copying: all 10 questions

Quiz: References and Copying · Question 9 of 10

What does this print? (code)

What does this print?

s = "hi"
t = s
s += "!"
print(t)
  1. A.hi
  2. B.hi!
  3. C.!
  4. D.An error
Answer & explanation

Correct answer: hi

Strings are immutable, so += builds a new string for s. t still points to the old "hi".

Can you get the rest right without peeking?

Take the timed Quiz: References and Copying quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →