How to Remove an Item in a Set in Python


In this example we will show 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

How to Remove an Item in a Set in Python


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

Source Code

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

my_set.remove('c')

print(my_set)

Output:

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