course content

Course Content

Python Data Structures

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

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


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.

Everything was clear?

Section 4. Chapter 5
toggle bottom row