E = {0, 2, 4, 6, 8};
N = {1, 2, 3, 4, 5};
# set union
print("Union of E and N is",E | N)
# set intersection
print("Intersection of E and N is",E & N)
# set difference
print("Difference of E and N is",E - N)
# set symmetric difference
print("Symmetric difference of E and N is",E ^ N)
Вывод результата:
('Union of E and N is', set([0, 1, 2, 3, 4, 5, 6, 8]))
('Intersection of E and N is', set([2, 4]))
('Difference of E and N is', set([0, 6, 8]))
('Symmetric difference of E and N is', set([0, 1, 3, 5, 6, 8]))


2015-11-29 • Просмотров [ 139 ]