Contenido del Curso
Python Data Structures
Python Data Structures
Remove() 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.
Tarea
You have the following set:
After modifying the set, it should look like this:
Achieve this using the remove()
method.
¿Todo estuvo claro?
Contenido del Curso
Python Data Structures
Python Data Structures
Remove() 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.
Tarea
You have the following set:
After modifying the set, it should look like this:
Achieve this using the remove()
method.
¿Todo estuvo claro?