Q. Read the following pieces of code. Determine whether they will be executed successfully or not. If yes, show the result that would be printed. If not, explain why not.
(a)
myTuple1 = (1,2,3)
myTuple1.append(4)
print(myTuple1)
(b)
myTuple2 = (1,2,3)
myTuple3 = (4)
print(myTuple2+myTuple3)
(c)
myList = [0,3,4,1]
myList.remove(3)
print(mylist)
Answer :-
(a) It will give error because tuple is immutable.
(b) It will give error because tuple and integer cannot concatenate.
(c) Output :-
[0, 4, 1]
>>>
Hey but in 'b', 4 is in parenthesis, i.e., in a tuple, right?
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )