How can you add an extra element to a tuple ?
7 Likes
We can use the concatenation operator to add an extra element to a tuple as shown below. As tuples are immutable so they cannot be modified in place.
For example:
t=(1,2,3) t_append = t + (4,) print(t) print(t_append)
Output:
(1,2,3) (1,2,3,4)
Answered By
4 Likes
How is an empty tuple created ?
How is a tuple containing just one element created ?
When would you prefer tuples over lists ?
What is the difference between (30) and (30,) ?