How to Remove an Item in a Set in Python


In this example, we will learn how to remove an item in a set using the discard() method in Python.

Source Code

my_set = {'a', 'b', 1, 'c'}

my_set.discard('c')

print(my_set)

Output:

{1, 'b', 'a'}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement