<jupyter_start><jupyter_text>All the IPython Notebooks in this lecture series by Dr. <NAME> are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/006_Python_Sets_Methods)**  Python Set `union()`The **`union()`** method returns a new set with distinct elements from all the sets.The union of two or more sets is the set of all distinct elements present in all the sets. For example:```pythonA = {1, 2}B = {2, 3, 4}C = {5}Then,A∪B = B∪A = {1, 2, 3, 4}A∪C = C∪A = {1, 2, 5}B∪C = C∪B = {2, 3, 4, 5}A∪B∪C = {1, 2, 3, 4, 5}``` **Syntax**:```pythonA.union(*other_sets)```>**Note:** **`*`** is not part of the syntax. It is used to indicate that the method can take 0 or more arguments.  Return Value from `union()`* The **`union()`** method returns a new set with elements from the set and all other sets (passed as an argument).* If the argument is not passed to **`union()`**, it returns a shallow copy of the set.<jupyter_code># Example 1: Working of union()

A = {'a', 'c', 'd'}
B = {'c', 'd', 2 }
C = {1, 2, 3}

print('A U B =', A.union(B))
print('B U C =', B.union(C))
print('A U B U C =', A.union(B, C))
print('A.union() =', A.union())<jupyter_output>A U B = {'a', 2, 'd', 'c'}
B U C = {1, 2, 3, 'd', 'c'}
A U B U C = {1, 'a', 2, 3, 'd', 'c'}
A.union() = {'a', 'd', 'c'}<jupyter_text>You can also find the union of sets using the **`|`** operator.<jupyter_code># Example 2: Set Union Using the | Operator

A = {'a', 'c', 'd'}
B = {'c', 'd', 2 }
C = {1, 2, 3}

print('A U B =', A| B)
print('B U C =', B | C)
print('A U B U C =', A | B | C)<jupyter_output>A U B = {'a', 2, 'd', 'c'}
B U C = {1, 2, 3, 'd', 'c'}
A U B U C = {1, 'a', 2, 3, 'd', 'c'}
{'fraction_non_alphanumeric': 0.2244776119402985, 'fraction_numerical': 0.03164179104477612, 'mean_word_length': 3.943952802359882, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '394553', 'license': 'MIT', 'n_tokens_mistral': 733, 'n_tokens_neox': 688, 'n_words': 271, 'path': '006_Python_Sets_Methods/016_Python_Set_union().ipynb', 'repo_name': 'Maxc390/python-discrete-structures', 'size': '1681'}