chevron_left
Set Operations
0
0
0
new
Python Set | union method
Programming
chevron_rightPython
chevron_rightOperations
chevron_rightSet Operations
schedule Jul 1, 2022
Last updated Python
Tags tocTable of Contents
expand_more Python's set.union(~)
method returns a new set with elements from all the provided sets.
Parameters
1. sets
| set
| optional
The sets from which we will include elements from.
Return value
A new set with elements from all the provided sets.
Examples
Basic usage
To return a new set with all elements from sets a
, b
, c
:
a = {'dog', 'cat'}b = {'sheep', 'dog'}c ={'mouse', 'dog'}
a.union(b, c)
{'cat', 'dog', 'mouse', 'sheep'}
We can see that we return a new set containing all distinct elements from sets a
, b
, c
. By definition, Sets do not allow duplicates values, hence 'dog'
only appears once in the returned set.
Published by Arthur Yanagisawa
Edited by 0 others
Did you find this page useful?
Ask a question or leave a feedback...
Official Python Documentation
https://docs.python.org/3/library/stdtypes.html#frozenset.union
0
0
0
Enjoy our search