course content

Course Content

Python Data Structures

Adding Items Adding Items

To add elements to a tuple, you can use the same approach that's effective for deletion. Since tuples are immutable, we can't directly add an element to them without encountering an error. However, by converting the tuple to a list, you can easily make the desired additions. Let's delve into an example.

Another way to add an element to a tuple is by concatenating it with another tuple. This is something we explored a few chapters back. If you want to add one or more elements, simply create a new tuple with these elements and combine it with the original tuple. Here's an illustrative example.


You currently have this tuple:

Your goal is to obtain the following tuple:

by converting the tuple into a list.

Everything was clear?

Section 3. Chapter 6
toggle bottom row