Languages
[Edit]
EN

Python - add sets

0 points
Created by:
jarlh
635

In this article, we would like to show you how to add two sets together in Python.

Quick solution:

set1.update(set2)

 

Practical example

In this example, we use update() method to add my_set2 to my_set1.

my_set1 = {'A', 'B', 'C'}
my_set2 = {'D', 'E'}

my_set1.update(my_set2)

print(my_set1)  # {'B', 'C', 'E', 'D', 'A'}

Output:

{'B', 'C', 'E', 'D', 'A'}
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