Computer Science
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.
Related Questions
Predict the output.
tuple1 = ('Python') * 3 print(type(tuple1))
Predict the output.
x = (1, (2, (3, (4,)))) print(len(x)) print( x[1][0] ) print( 2 in x ) y = (1, (2, (3,), 4), 5) print( len(y) ) print( len(y[1])) print( y[2] + 50 ) z = (2, (1, (2, ), 1), 1) print( z[z[z[0]]])
What will be the output of the following code snippet?
Tup1 = ((1, 2),) * 7 print(len(Tup1[3:8]))
Write a Python program that creates a tuple storing first 9 terms of Fibonacci series.