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

Contenido del Curso

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.

Tarea

You have the following set:

After modifying the set, it should look like this:

Achieve this using the remove() method.

¿Todo estuvo claro?

Sección 4. Capítulo 5
toggle bottom row
course content

Contenido del Curso

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.

Tarea

You have the following set:

After modifying the set, it should look like this:

Achieve this using the remove() method.

¿Todo estuvo claro?

Sección 4. Capítulo 5
toggle bottom row
some-alt