Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Remove() and Discard() Methods | Set
course content

Зміст курсу

Python Data Structures

Remove() and Discard() MethodsRemove() and Discard() Methods

In sets, you can remove elements using the remove() method.

Note

If the element you're trying to remove isn't in the set, you'll get a KeyError.

There's another way to get rid of items from a set: the discard() method. Unlike remove(), discard() won't throw a KeyError if the item you want to remove isn't there — it just leaves the set as is.

Завдання

You have the following set:

After modifying the set, it should look like this:

Achieve this using the remove() method.

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

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

Зміст курсу

Python Data Structures

Remove() and Discard() MethodsRemove() and Discard() Methods

In sets, you can remove elements using the remove() method.

Note

If the element you're trying to remove isn't in the set, you'll get a KeyError.

There's another way to get rid of items from a set: the discard() method. Unlike remove(), discard() won't throw a KeyError if the item you want to remove isn't there — it just leaves the set as is.

Завдання

You have the following set:

After modifying the set, it should look like this:

Achieve this using the remove() method.

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

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