Introduction
Set basics
6. Deleting elements – discard()
Relationships between sets
Summary

Instruction

Perfect! Removing elements from sets is also very easy. There are several ways to do it. Let's start with the discard() method:

favorite_movies = {'Halloween', 'A Star Is Born', 'Hocus Pocus'}
favorite_movies.discard('Hocus Pocus')

The discard() method deletes a given element from a set. If the element we're trying to delete is not present in the set, Python simply ignores the method invocation and does nothing.

Exercise

Unfortunately, Nancy Silva quit. Delete her from the set, and print the set.

Stuck? Here's a hint!

Use:

new_branch_employees.discard('Nancy Silva')