In [3]:
c = set()
In [4]:
c.add(1)
In [5]:
c.add(2)
In [6]:
c.add(3)
In [7]:
c
Out[7]:
In [8]:
c.discard(1)
In [9]:
c
Out[9]:
In [10]:
c.add(1)
In [11]:
c2 = c
In [12]:
c2.add(4)
In [13]:
c
Out[13]:
In [14]:
c2 = c.copy()
In [15]:
c2
Out[15]:
In [16]:
c
Out[16]:
In [17]:
c2.discard(4)
In [18]:
c2
Out[18]:
In [19]:
c
Out[19]:
In [20]:
c2.clear()
In [21]:
c2
Out[21]:
In [41]:
c1 = {1,2,3}
c2 = {3,4,5}
c3 = {-1,99}
c4 = {1,2,3,4,5}
In [26]:
c1.isdisjoint(c2)
Out[26]:
In [29]:
c3.issubset(c4)
Out[29]:
In [33]:
c3.issuperset(c1)
Out[33]:
In [41]:
c1 = {1,2,3}
c2 = {3,4,5}
c3 = {-1,99}
c4 = {1,2,3,4,5}
In [35]:
c1.union(c2) == c4
Out[35]:
In [36]:
c1.union(c2)
Out[36]:
In [37]:
c1
Out[37]:
In [38]:
c2
Out[38]:
In [39]:
c1.update(c2)
In [40]:
c1
Out[40]:
In [42]:
c1 = {1,2,3}
c2 = {3,4,5}
c3 = {-1,99}
c4 = {1,2,3,4,5}
In [43]:
c1.difference(c2)
Out[43]:
In [44]:
c1.difference_update(c2)
In [45]:
c1
Out[45]:
In [7]:
c1 = {1,2,3}
c2 = {3,4,5}
c3 = {-1,99}
c4 = {1,2,3,4,5}
In [8]:
c1.intersection(c2)
Out[8]:
In [9]:
c1.intersection_update(c2)
c1
Out[9]:
In [7]:
c1 = {1,2,3}
c2 = {3,4,5}
c3 = {-1,99}
c4 = {1,2,3,4,5}
In [48]:
c1.symmetric_difference(c2)
Out[48]: