Adding Items Adding Items

In order to add some elements to the tuple, you can use the same trick that works for deleting. Since a tuple is an immutable data structure, we cannot directly add an element to a tuple; otherwise we will get an error. But if we go from the tuple to the list, then this can be done very easily. Let's take a look at an example.

Another method of adding an element to a tuple is adding a tuple to a tuple, that is, a concatenation of tuples, which we learned several chapters ago. In this case, if we want to add one or several elements, we should create a new tuple with these elements and add them to the existing one. Take a look at the example.


You have the tuple:

You have to get the tuple:

by converting the tuple into a list.

Everything was clear?

Section 3. Chapter 6
toggle bottom row