Skip to main content
Home
  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact
programsbuzz facebook programsbuzz twitter programsbuzz linkedin
  • Log in

Main navigation

  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact

Python: Union of Sets

Profile picture for user devanshi.srivastava
Written by devanshi.srivastava on 07/03/2021 - 16:49

Union of two given sets is the smallest set which contains all the elements of both the sets. It return a set that contains all items from the original set, and all items from the specified sets.

If an item is present in more than one set, the result will contain only one appearance of this item.

Syntax:

set.union(set1, set2...)

Parameters:

It takes any number of sets, which can be given.

Returns:

  • It returns a set, which has the union of all sets(set1, set2, set3…) with set1.
  • It returns a copy of set1 only if no parameter is passed.

Example:

A = {1,2,3}
B = {4,5}
C = {6,7,8}

print('A U B =', A.union(B))
print('A U C =',A.union(C))
print('B U C =',B.union(C))
print('A U B U C =',A.union(B,C))

Output:

A U B = {1, 2, 3, 4, 5}
A U C = {1, 2, 3, 6, 7, 8}
B U C = {4, 5, 6, 7, 8}
A U B U C = {1, 2, 3, 4, 5, 6, 7, 8}
Related Content
Python Tutorial
Python: Sets
Python: Sets Operation List
Tags
Python
  • Log in or register to post comments

Choose Your Technology

  1. Agile
  2. Apache Groovy
  3. Apache Hadoop
  4. Apache HBase
  5. Apache Spark
  6. Appium
  7. AutoIt
  8. AWS
  9. Behat
  10. Cucumber Java
  11. Cypress
  12. DBMS
  13. Drupal
  14. GitHub
  15. GitLab
  16. GoLang
  17. Gradle
  18. HTML
  19. ISTQB Foundation
  20. Java
  21. JavaScript
  22. JMeter
  23. JUnit
  24. Karate
  25. Kotlin
  26. LoadRunner
  27. matplotlib
  28. MongoDB
  29. MS SQL Server
  30. MySQL
  31. Nightwatch JS
  32. PactumJS
  33. PHP
  34. Playwright
  35. Playwright Java
  36. Playwright Python
  37. Postman
  38. Project Management
  39. Protractor
  40. PyDev
  41. Python
  42. Python NumPy
  43. Python Pandas
  44. Python Seaborn
  45. R Language
  46. REST Assured
  47. Ruby
  48. Selenide
© Copyright By iVagus Services Pvt. Ltd. 2023. All Rights Reserved.

Footer

  • Cookie Policy
  • Privacy Policy
  • Terms of Use