course content

Course Content

Python Data Structures

Delete a Tuple Delete a Tuple

Keep in mind that a tuple is an immutable data structure, which means you can't make changes to it once it's been created. This includes removing items from the tuple. However, you can delete the entire tuple using the del statement.

Removing Items


There's a workaround if you want to remove items from a tuple. First, you need to convert the tuple into a list since lists are mutable and can be modified. After making the desired changes to the list, you can then convert it back into a tuple.

Let's dive into an example.


Suppose you have the following tuple:

You want to remove the following items:
banana, grape, peach

Everything was clear?

Section 3. Chapter 4
toggle bottom row