How to Add One Item to a Set in Python


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

Source Code

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

my_set.add('d')
print(my_set)

Output:

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