Languages
[Edit]
EN

Python - add set items

0 points
Created by:
Admin Dirask Community
4380

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'}
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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