Languages
[Edit]
EN

Python - add set items

0 points
Created by:
Admin Dirask Community
1810

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'}

Python - set (popular problems)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join