Computer Science
Carefully read the given code fragments and figure out the errors that the code may produce.
t = ('a', 'b', 'c', 'd', 'e')
t[0] = 'A'
Python Tuples
2 Likes
Answer
Output
TypeError: 'tuple' object does not support item assignment
Explanation
Tuple is a collection of ordered and unchangeable items as they are immutable. So once a tuple is created we can neither change nor add new values to it.
Answered By
2 Likes
Related Questions
What does each of the following expressions evaluate to? Suppose that T is the tuple containing :
("These", ["are" , "a", "few", "words"] , "that", "we", "will" , "use")
T[1][0: :2]
"a" in T[1][0]
T[:1] + [1]
T[2::2]
T[2][2] in T[1]
Carefully read the given code fragments and figure out the errors that the code may produce.
t = ('a', 'b', 'c', 'd', 'e') print(t[5])
Carefully read the given code fragments and figure out the errors that the code may produce.
t1 = (3) t2 = (4, 5, 6) t3 = t1 + t2 print (t3)
Carefully read the given code fragments and figure out the errors that the code may produce.
t1 = (3,) t2 = (4, 5, 6) t3 = t1 + t2 print (t3)