sets operations python code example
Example 1: python sets
my_set = {}
my_set = set()
set_example = {1,3,2,5,3,6}
print(set_example)
Example 2: set except python
A = {0, 2, 4, 6, 8};
B = {1, 2, 3, 4, 5};
print("Union :", A | B)
print("Intersection :", A & B)
print("Difference :", A - B)
print("Symmetric difference :", A ^ B)
Example 3: sets in python
The simplest way to create set is:
1. from list
code:
s = [1,2,3]
set = set(s)
print(set)
2. s,add() method
code:
set.add(1)
set.add(2)
set.remove(2)
print(set) // 1
3. Set conatins unique elements