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

Course Content

Python Data Structures

Python Data Structures

1. List
2. Dictionary
3. Tuple
4. Set

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

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

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.

12345
tuple_1 = (10, 20, 30, 40, 50, 60, 70) another_tuple = (80,) tuple_1 += another_tuple print(tuple_1)
copy

Task

You currently have this tuple:

Your goal is to obtain the following tuple:

by converting the tuple into a list.

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 6
toggle bottom row

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

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

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.

12345
tuple_1 = (10, 20, 30, 40, 50, 60, 70) another_tuple = (80,) tuple_1 += another_tuple print(tuple_1)
copy

Task

You currently have this tuple:

Your goal is to obtain the following tuple:

by converting the tuple into a list.

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 6
toggle bottom row

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

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

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.

12345
tuple_1 = (10, 20, 30, 40, 50, 60, 70) another_tuple = (80,) tuple_1 += another_tuple print(tuple_1)
copy

Task

You currently have this tuple:

Your goal is to obtain the following tuple:

by converting the tuple into a list.

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!

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.

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

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.

12345
tuple_1 = (10, 20, 30, 40, 50, 60, 70) another_tuple = (80,) tuple_1 += another_tuple print(tuple_1)
copy

Task

You currently have this tuple:

Your goal is to obtain the following tuple:

by converting the tuple into a list.

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