EN
Python - add set items
0
points
In this article, we would like to show you how to add set items in Python.
Quick solution:
my_set.add('new item')
Practical example using add()
method
In this example, we use add()
method to add an item to the set.
my_set = {'A', 'B', 'C'}
my_set.add('D')
print(my_set) # {'C', 'B', 'A', 'D'}
Output:
{'C', 'B', 'A', 'D'}