>>> s=set([1,2,3,4,5,1,2])
>>> s
set([1, 2, 3, 4, 5])
>>> fs=frozenset(s)
>>> fs
frozenset([1, 2, 3, 4, 5])
>>> fs.issubset(s);fs.issuperset(s)
True
True
>>> t=set([1,2,6,7,8,9])
>>> s.intersection(t), s&t
(set([1, 2]), set([1, 2]))
>>> s.union(t), s|t
(set([1, 2, 3, 4, 5, 6, 7, 8, 9]), set([1, 2, 3, 4, 5, 6, 7, 8, 9]))
>>> s.difference(t), s-t
(set([3, 4, 5]), set([3, 4, 5]))
>>> s.symmetric_difference
>>> s.symmetric_difference(t), s^t
(set([3, 4, 5, 6, 7, 8, 9]), set([3, 4, 5, 6, 7, 8, 9]))
>>> s.copy()
set([1, 2, 3, 4, 5])
>>> fs.copy()
frozenset([1, 2, 3, 4, 5])
>>> r=s.copy()
>>> r
set([1, 2, 3, 4, 5])
>>> s.update(t), s|=t
SyntaxError: illegal expression for augmented assignment
>>> s.update(t); s|=t
>>> s
set([1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> s.add(1)
>>> s.add(44)
>>> s
set([1, 2, 3, 4, 5, 6, 7, 8, 9, 44])
>>> s.remove(1)
>>> s
set([2, 3, 4, 5, 6, 7, 8, 9, 44])
>>> s.pop()
2
>>> s
set([3, 4, 5, 6, 7, 8, 9, 44])
>>> s.clear()
>>> s
set([])
>>> s
set([1, 2, 3, 4, 5])
>>> fs=frozenset(s)
>>> fs
frozenset([1, 2, 3, 4, 5])
>>> fs.issubset(s);fs.issuperset(s)
True
True
>>> t=set([1,2,6,7,8,9])
>>> s.intersection(t), s&t
(set([1, 2]), set([1, 2]))
>>> s.union(t), s|t
(set([1, 2, 3, 4, 5, 6, 7, 8, 9]), set([1, 2, 3, 4, 5, 6, 7, 8, 9]))
>>> s.difference(t), s-t
(set([3, 4, 5]), set([3, 4, 5]))
>>> s.symmetric_difference
>>> s.symmetric_difference(t), s^t
(set([3, 4, 5, 6, 7, 8, 9]), set([3, 4, 5, 6, 7, 8, 9]))
>>> s.copy()
set([1, 2, 3, 4, 5])
>>> fs.copy()
frozenset([1, 2, 3, 4, 5])
>>> r=s.copy()
>>> r
set([1, 2, 3, 4, 5])
>>> s.update(t), s|=t
SyntaxError: illegal expression for augmented assignment
>>> s.update(t); s|=t
>>> s
set([1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> s.add(1)
>>> s.add(44)
>>> s
set([1, 2, 3, 4, 5, 6, 7, 8, 9, 44])
>>> s.remove(1)
>>> s
set([2, 3, 4, 5, 6, 7, 8, 9, 44])
>>> s.pop()
2
>>> s
set([3, 4, 5, 6, 7, 8, 9, 44])
>>> s.clear()
>>> s
set([])
Comments
Post a Comment