Python built-in functions -- set & amp; frozenset sample code can be referred to below for requirements
Python built-in functions -- set & frozenset
Set
Set () set object instantiation >>> set ('ADD') set (['A', 'D']) >>> set ('Python '). add ('Hello') >>> print set ('Python '). add ('Hello') None >>> a = set ('Python') >>> aset (['H', 'O', 'n', 'P ', 'T', 'y'])>. add ('Hello') >>> aset (['H', 'O', 'n', 'P', 'T', 'y ', 'Hello']) >>>. update ('Python') >>> aset (['H', 'O', 'n', 'P', 'T', 'y ', 'Hello']) >>>. update ('Hello') >>> aset (['e', 'H', 'L', 'O', 'n', 'P', 'T ', 'Y', 'Hello']) >>>. remo Ve ('Hello') >>> aset (['e', 'H', 'L', 'O', 'n', 'P', 'T ', 'Y']) >>> B = set ('Hello') >>> bset (['H', 'e', 'L ', 'O']) >>> a-bset (['y', 'P', 'T', 'n']) >>> a & bset (['H', 'e', 'L', 'O'])> a | bset (['e', 'H ', 'L', 'O', 'n', 'P', 'T', 'y'])>! = BTrue >>> a === bFalse >>> B in aFalse >>> a in bFalse >>>> c = set ('hell ') >>> c in bFalse >>> bset (['H', 'e', 'L', 'O']) >>> cset (['H', 'e ', 'L']) >>> 'H' in cTrue >>> 'P' in cFalse
Frozenset
Frozenset ([iterable]) generates an immutable set >>> a = frozenset (range (10) >>> afrozenset ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])>. remove (0) Traceback (most recent call last): File"
", Line 1, in
A. remove (0) AttributeError: 'frozenset' object has no attribute 'delete' >>> B = set (range (10) >>> bset ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])> B. remove (1) >>> bset ([0, 2, 3, 4, 5, 6, 7, 8, 9])
The above is the content of the Python built-in function -- set & frozenset. For more information, see PHP Chinese network (www.php1.cn )!