Python built-in function--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 ') >>> A.add (' hello ') >>> aset ([' H ', ' o ', ' n ', ' P ', ' t ', ' y ', ' hello ']) >>> a.update (' python ') >>> Aset ([' H ', ' o ', ' n ', ' P ', ' t ', ' y ', ' hello ']) >>> a.update (' hello ') >>> aset ([' E ', ' h ', ' l ', ' o ', ' n ', ' P ') , ' t ', ' y ', ' hello ']) >>> a.remove (' 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 & Bs ET ([' H ', ' e ', ' l ', ' o ']) >>> a | bSET ([' E ', ' h ', ' l ', ' o ', ' n ', ' P ', ' t ', ' y ']) >>> a! = btrue>>> A = = bfalse>>> B in afalse>& Gt;> 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]) produces an immutable set>>> a = Frozenset (range) >>> Afrozenset ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]) >>> a.remove (0) Traceback (most recent): File "<pyshell#189>", line 1, in <module>< C2/>a.remove (0) Attributeerror: ' Frozenset ' object has no attribute ' remove ' >>> B = set (range) >>> 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 python built-in function--set&frozenset content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!