CBSE Class 11 Computer Science Question 96 of 114

Tuples — Question 33

Back to all questions
33
Question

Question 9

What will the following code produce ?

Tup1 = (1,) * 3
Tup1[0] = 2 
print(Tup1)
Answer
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.