Python sets can also be changed by calling their methods. There are two methods that see the most frequent use:
add
method adds an element to the set. For example, if example
is
{1, 2}
, the call example.add(0)
would change example
to
{0, 1, 2}
.discard
method removes an element from the set if possible. For instance, if
example
is {1, 2}
, the call example.discard(2)
would change
example
to {1}
. Similarly, if sample
is {1, 2}
, the call
sample.discard(3)
would do nothing because 3
is already not in the set.Fill in the placeholders so that the actual outputs match the expected outputs.