Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

Python Set Union

  • Safa MulaniSafa Mulani
  • January 19, 2020
  • Python Set
Python Set Union

Union basically represents all the distinct elements of the corresponding sets altogether.

Python Set union() method finds the union of the sets and represents a new set which contains all the items from the corresponding input sets.

Note: If a set contains an element that appears more than once, then the output represented contains only a single appearance of the particular element.

Syntax:

set1.union(set2, set3,......, setN)

Basic understanding of Python Set Union

info = {'Safa', 'Aman', 'Divya', 'Elen'}
info1 = {'Safa', 'Aryan'}

print(info.union(info1))

Output:

{'Aman', 'Safa', 'Divya', 'Aryan', 'Elen'}

Python Set Union using “|” operator

The “|” operator can also be used to find the union of the input sets.

info = {'Safa', 'Aman', 'Diya'}
info1 = {'Varun', 'Rashi', 54 }

print(info | info1)

Output:

{'Diya', 'Aman', 'Safa', 54, 'Varun', 'Rashi'}

Union of Multiple Python Sets

Either of the following techniques can be used to find the union of multiple sets:

  • Passing multiple sets as arguments to the union() method
  • By creating a chain of union() method calls

1. Union of multiple sets using multiple sets as arguments

info = {12, 14, 15, 17}
info1 = {35, 545}
info2 = {'Safa','Aman'}

print(info.union(info1, info2))

Output:

{'Safa', 17, 545, 35, 'Aman', 12, 14, 15}

2. Union of multiple sets by creating a chain of union() method calls

info = {12, 14, 15, 17}
info1 = {35, 545}
info2 = {'Safa','Aman'}

print(info.union(info1).union(info2))


Output:

{'Aman', 17, 545, 35, 'Safa', 12, 14, 15}

Conclusion

Thus, in this article, we have understood and implemented ways to find the union of sets in Python.


References

  • Python Sets
  • Sets Documentation
Safa Mulani
Safa Mulani

An enthusiast in every forthcoming wonders!

Articles: 189
Python Add to Dictionary
Previous Post Python Add to Dictionary
Next Post Python bytes()
Python bytes()

Related Posts

Python Set Intersection: Methods and Operators

Python Set Intersection: Methods and Operators

  • November 28, 2026
Python Nested Sets: Create a Set of Groups

Python Nested Sets: Create a Set of Groups

  • November 12, 2026
Python Sets: Fix the Indexing TypeError

Python Sets: Fix the Indexing TypeError

  • November 4, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.