Delete a Tuple Delete a Tuple

Remember that a tuple is a fixed data structure, so any changes to the created tuple are not allowed, including removing items from the tuple. But we can delete the entire tuple. To do so, we have the del method.

Remove Items


There is one trick to removing items from a tuple. First, we need to turn the tuple into a list. Because the list is a mutable data structure, we can modify the list. Then, you can remove the items you need from the list and then return the list to the tuple.

Let's look at the example.


You have the following tuple:

You need to remove some items, namely:
banana, grape, peach

Everything was clear?

Section 3. Chapter 4
toggle bottom row