33
Question Question 9
What will the following code produce ?
Tup1 = (1,) * 3
Tup1[0] = 2
print(Tup1)Output
TypeError: 'tuple' object does not support item assignment
Explanation
(1,) is a single element tuple. * operator repeats (1,) three times to form (1, 1, 1) that is stored in Tup1.Tup1[0] = 2 will throw an error, since tuples are immutable. They cannot be modified in place.