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

Зміст курсу

Python Data Structures

Adding Items Adding 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.

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.

Завдання

You currently have this tuple:

Your goal is to obtain the following tuple:

by converting the tuple into a list.

Все було зрозуміло?

Секція 3. Розділ 6
toggle bottom row
course content

Зміст курсу

Python Data Structures

Adding Items Adding 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.

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.

Завдання

You currently have this tuple:

Your goal is to obtain the following tuple:

by converting the tuple into a list.

Все було зрозуміло?

Секція 3. Розділ 6
toggle bottom row
some-alt