Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Delete a Tuple | Tuple
Python Data Structures
course content

Course Content

Python Data Structures

Python Data Structures

1. List
2. Dictionary
3. Tuple
4. Set
5. For deleting

bookDelete 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.

1234
tuple_1 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) del tuple_1 print(tuple_1)
copy

Removing Items

Note

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.

12345
tuple_1 = (10, 20, 30, 40, 50, 60, 70 ,80) list_1 = list(tuple_1) list_1.remove(80) tuple_1 = tuple(list_1) print(tuple_1)
copy

Task

Suppose you have the following tuple:

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 4
toggle bottom row

bookDelete 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.

1234
tuple_1 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) del tuple_1 print(tuple_1)
copy

Removing Items

Note

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.

12345
tuple_1 = (10, 20, 30, 40, 50, 60, 70 ,80) list_1 = list(tuple_1) list_1.remove(80) tuple_1 = tuple(list_1) print(tuple_1)
copy

Task

Suppose you have the following tuple:

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 4
toggle bottom row

bookDelete 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.

1234
tuple_1 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) del tuple_1 print(tuple_1)
copy

Removing Items

Note

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.

12345
tuple_1 = (10, 20, 30, 40, 50, 60, 70 ,80) list_1 = list(tuple_1) list_1.remove(80) tuple_1 = tuple(list_1) print(tuple_1)
copy

Task

Suppose you have the following tuple:

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

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.

1234
tuple_1 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) del tuple_1 print(tuple_1)
copy

Removing Items

Note

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.

12345
tuple_1 = (10, 20, 30, 40, 50, 60, 70 ,80) list_1 = list(tuple_1) list_1.remove(80) tuple_1 = tuple(list_1) print(tuple_1)
copy

Task

Suppose you have the following tuple:

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 3. Chapter 4
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt