>>> a={3,"a",2.1,1}>>> a.pop()>>> a.pop()>>> a.clear()>>> aset()>>> a.pop()Traceback (most recent call last): File "<input>", line 1,in<module>KeyError:'pop from an empty set'
集合的工厂函数
classset(object):""" set() -> new empty set object set(iterable) -> new set object Build an unordered collection of unique elements. """defadd(self,*args,**kwargs): # real signature unknown""" Add an element to a set. This has no effect if the element is already present. """passdefclear(self,*args,**kwargs): # real signature unknown""" Remove all elements from this set. """passdefcopy(self,*args,**kwargs): # real signature unknown""" Return a shallow copy of a set. """passdefdifference(self,*args,**kwargs): # real signature unknown""" 相当于s1-s2 Return the difference of two or more sets as a new set. (i.e. all elements that are in this set but not the others.) """passdefdifference_update(self,*args,**kwargs): # real signature unknown""" Remove all elements of another set from this set. """passdefdiscard(self,*args,**kwargs): # real signature unknown""" 与remove功能相同,删除元素不存在时不会抛出异常 Remove an element from a set if it is a member. If the element is not a member, do nothing. """passdefintersection(self,*args,**kwargs): # real signature unknown""" 相当于s1&s2 Return the intersection of two sets as a new set. (i.e. all elements that are in both sets.) """passdefintersection_update(self,*args,**kwargs): # real signature unknown""" Update a set with the intersection of itself and another. """passdefisdisjoint(self,*args,**kwargs): # real signature unknown""" Return True if two sets have a null intersection. """passdefissubset(self,*args,**kwargs): # real signature unknown""" 相当于s1<=s2 Report whether another set contains this set. """passdefissuperset(self,*args,**kwargs): # real signature unknown""" 相当于s1>=s2 Report whether this set contains another set. """passdefpop(self,*args,**kwargs): # real signature unknown""" Remove and return an arbitrary set element. Raises KeyError if the set is empty. """passdefremove(self,*args,**kwargs): # real signature unknown""" Remove an element from a set; it must be a member. If the element is not a member, raise a KeyError. """passdefsymmetric_difference(self,*args,**kwargs): # real signature unknown""" 相当于s1^s2 Return the symmetric difference of two sets as a new set. (i.e. all elements that are in exactly one of the sets.) """passdefsymmetric_difference_update(self,*args,**kwargs): # real signature unknown""" Update a set with the symmetric difference of itself and another. """passdefunion(self,*args,**kwargs): # real signature unknown""" 相当于s1|s2 Return the union of sets as a new set. (i.e. all elements that are in either set.) """passdefupdate(self,*args,**kwargs): # real signature unknown""" Update a set with the union of itself and others. """pass...略...