Course Content
Python Data Structures
Python Data Structures
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.
tuple_1 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) del tuple_1 print(tuple_1)
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.
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)
Task
Suppose you have the following tuple:
You want to remove the following items:banana
, grape
, peach
Thanks for your feedback!
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.
tuple_1 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) del tuple_1 print(tuple_1)
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.
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)
Task
Suppose you have the following tuple:
You want to remove the following items:banana
, grape
, peach
Thanks for your feedback!
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.
tuple_1 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) del tuple_1 print(tuple_1)
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.
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)
Task
Suppose you have the following tuple:
You want to remove the following items:banana
, grape
, peach
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.
tuple_1 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) del tuple_1 print(tuple_1)
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.
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)
Task
Suppose you have the following tuple:
You want to remove the following items:banana
, grape
, peach