Languages
[Edit]
EN

Python - add sets

0 points
Created by:
jarlh
295

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

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