Python tutorial
method | description |
The following Arithmetic and bitwise operators can be applied on Sets.
>>> set1=set('abcd') >>> set2=set('abcdef')
>>> set1 {'b', 'd', 'a', 'c'} >>> set2 {'e', 'f', 'b', 'd', 'a', 'c'} >>>
The set that contains all elements of two or more sets
>>> set1 | set2 {'e', 'f', 'b', 'd', 'a', 'c'} >>>
The set that contains all elements common to all sets
>>> set1 & set2 {'b', 'd', 'a', 'c'} >>>
The set contains all elements from set1 that doesnot exists in set2
>>> set1 - set2 set() >>> >>>set2 - set1 {'e', 'f'}
The set that contains all elements belonging to either of given two sets but not to the both;
>>> set1 ^ set2 {'e', 'f'} >>> >>>set2 ^ set1 {'e', 'f'}
ADS