What will be the result returned? t = (3, 4, ['a', 'b']) t[2].append ('c') print(t)
- User
What will be the result returned?
t = (3, 4, ['a', 'b']) t[2].append ('c') print(t)
- Assistant
The result returned will be:
(3, 4, ['a', 'b', 'c'])
Notice that even though tuples are immutable, the list inside the tuple is mutable and can be modified. So when we append 'c' to the list in the tuple, we are modifying the list in place, but we are not modifying the tuple itself.
- User
What will be the result?
myT (9, 11, 6, 1, 5, 4) print (sorted (myT))
- Assistant
The result will be:
[1, 4, 5, 6, 9, 11]
Here, we have a tuple
myTwith the values(9, 11, 6, 1, 5, 4). We pass this tuple to thesorted()function, which returns a new sorted list of the elements in the tuple.Therefore, the output is a sorted list
[1, 4, 5, 6, 9, 11]. Note that the original tuplemyTis not modified.