Skip to content

Question 17

What is the output of the following code?

1
2
3
tup1 = ([1,2,3], 4,[5,6])
tup1[0][0] = 999
print(tup1[0])
Solution

In tup1, the elements are (in order of index): [1,2,3], 4, [5,6]. The one we want specifically is inside tup[0], i.e., [1,2,3]. Now inside this inner list, the element at index 0 (i.e., first element) is 1. Hence, we can deduce the start value of tup1[0][0] = 1.

Now following the reassignment of tup1[0][0] to be a value of 999, this effectively means that tup[0] = [999, 2, 3].

Answer
[999, 2, 3]