set()集合基本操作

运用频次:☆☆

set是一个无序且不重复元素集,基本操作如下:

1. 创建set集合,会自动转换成set类型

2. add():添加元素

 def add(self, *args, **kwargs): # real signature unknown
       # 添加元素
        """
        Add an element to a set.
        
        This has no effect if the element is already present.
        """
        pass

3. clear():清除元素

 def clear(self, *args, **kwargs): # real signature unknown
        #清除元素
        """ Remove all elements from this set. """
        pass

3. copy():浅拷贝

def copy(self, *args, **kwargs): # real signature unknown
        """ Return a shallow copy of a set. """
        pass

 4. difference():取差集,不更新原集合

def difference(self, *args, **kwargs): # real signature unknown
       # 取差集,不更新原集合,重新生成新的集合
        """
        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.)
        """
        pass

 5. difference_update():取差集,更新原集合

def difference_update(self, *args, **kwargs): # real signature unknown
       # 取差集,更新原集合,不生成新的集合
        """ Remove all elements of another set from this set. """
        pass

 6. discard():删除元素,更新原集合

def discard(self, *args, **kwargs): # real signature unknown
       # 删除指定元素,更新原集合
        """
        Remove an element from a set if it is a member.
        
        If the element is not a member, do nothing.
        """
        pass

 7. intersection():取交集,返回一个新的集合

def intersection(self, *args, **kwargs): # real signature unknown
       # 取交集,不更新原集合,重新生成新集合
        """
        Return the intersection of two sets as a new set.
        
        (i.e. all elements that are in both sets.)
        """
        pass

 8. intersection_update():取交集,更新原集合

def intersection_update(self, *args, **kwargs): # real signature unknown
      # 取交集,更新原集合
        """ Update a set with the intersection of itself and another. """
        pass

 9. isdisjoint():判断是否有交集,无则返回True

def isdisjoint(self, *args, **kwargs): # real signature unknown
       # 若无交集,则返回True
        """ Return True if two sets have a null intersection. """
        pass

 10. issubset():判断是否是子集,是则返回True

def issubset(self, *args, **kwargs): # real signature unknown
       # 判断另一集合是否包含该集合,是则返回True
        """ Report whether another set contains this set. """
        pass

 11. issuperset():判断是否是父集,是则返回True

def issuperset(self, *args, **kwargs): # real signature unknown
       # 判断该集合是否包含另一集合,是则返回True
        """ Report whether this set contains another set. """
        pass

 12. pop():随机删除一个元素并返回,更新原集合

def pop(self, *args, **kwargs): # real signature unknown
       # 随机删除一个元素并返回,更新原集合
        """
        Remove and return an arbitrary set element.
        Raises KeyError if the set is empty.
        """
        pass

 13. remove():删除元素,更新原集合

 def remove(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.
        """
        pass

 14. symmetric_difference():取差集,不更新原集合

 def symmetric_difference(self, *args, **kwargs): # real signature unknown
      # 取差集,返回一个新的集合,不更新原集合
        """
        Return the symmetric difference of two sets as a new set.
        
        (i.e. all elements that are in exactly one of the sets.)
        """
        pass

 15. symmetric_difference_update():取差集,更新原集合

 def symmetric_difference_update(self, *args, **kwargs): # real signature unknown
       # 取差集,更新原集合
        """ Update a set with the symmetric difference of itself and another. """
        pass

 16. union():取并集,不更新原集合

 def union(self, *args, **kwargs): # real signature unknown
       # 取并集,返回一个新的集合,不更新原集合
        """
        Return the union of sets as a new set.
        
        (i.e. all elements that are in either set.)
        """
        pass

 17. update():取并集,更新原集合

def update(self, *args, **kwargs): # real signature unknown
      # 取并集,更新原集合
        """ Update a set with the union of itself and others. """
        pass

 

posted on 2018-01-22 17:40  柠檬加醋  阅读(291)  评论(0编辑  收藏  举报

导航