Question 20
What is the output of the following code?
Solution
Initially, t1[1:] = ['b', 'c']. When reassigning t1[1:] to ['x', 'y', 'z'], it effectively means replacing every element after index 1 in t1 to take on those new values, meaning 'b' and 'c' are now no more.
Hence, t1 = ['a', 'x', 'y', 'z'] after this change.
Since t2 is a tuple utilizing shallow copies of t1, even if t2 was declared earlier before the change, the change propagates there.
Hence, t2 = (['a', 'x', 'y', 'z'], ['a', 'x', 'y', 'z']).